結果

問題 No.2496 LCM between Permutations
ユーザー umimelumimel
提出日時 2023-10-06 23:23:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,594 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 175,840 KB
実行使用メモリ 27,360 KB
平均クエリ数 953.97
最終ジャッジ日時 2023-10-06 23:23:11
合計ジャッジ時間 8,244 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,412 KB
testcase_01 AC 26 ms
23,412 KB
testcase_02 AC 26 ms
24,024 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 27 ms
23,400 KB
testcase_06 AC 26 ms
24,036 KB
testcase_07 AC 26 ms
23,400 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 26 ms
23,844 KB
testcase_14 WA -
testcase_15 AC 33 ms
24,384 KB
testcase_16 AC 35 ms
24,372 KB
testcase_17 AC 36 ms
23,856 KB
testcase_18 AC 170 ms
24,072 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 169 ms
23,556 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 264 ms
27,360 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60;
const int IINF = (1 << 30) - 1;

template<typename T> struct Edge{
    int to; T w;
    Edge(int to_, T w_=1){
        to = to_;
        w=w_;
    }
};
template<typename T> using Tree = vector<vector<Edge<T>>>;
template<typename T> using Graph = vector<vector<Edge<T>>>;
/* 容量&重み付きエッジ for Dinic */
template<typename T> struct REdge{
    int to;
    T cap;
    T cost;
    int rev;
    REdge(int to_, T cap_, T cost_=1){
        to = to_;
        cap = cap_;
        cost = cost_;
    }
    
    REdge(int to_, T cap_, T cost_, int rev_){
        to = to_;
        cap = cap_;
        cost = cost_;
        rev = rev_;
    }
};

/* 残余グラフ for Dinic */
template<typename T> using RGraph = vector<vector<REdge<T>>>;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    vector<vector<ll>> P(n, vector<ll>(n, 0));
    for(ll i=0; i<n; i++){
        for(ll j=0; j<n; j++){
            P[i][j] = (i+1)/__gcd(i+1, j+1)*(j+1);
        }
        sort(all(P[i]));
    }

    //1回目
    vector<ll> Q;
    for(ll j=1; j<=n; j++){
        cout << "? " << 1 << " " << j << endl;
        ll tmp; cin >> tmp;
        Q.pb(tmp);
    }
    vector<ll> SQ = Q;
    sort(all(SQ));

    ll X = 0;
    for(ll i=0; i<n; i++){
        bool ok = true;
        for(ll j=0; j<n; j++) if(SQ[j]!=P[i][j]) ok = false;

        if(ok){
            X = i;
            break;
        }
    }

    X++;
    ll B1 = 0;
    for(ll j=0; j<n; j++) if(Q[j]==X){
        B1 = j+1;
        break;
    }

    //質問2回目
    vector<ll> A;
    for(ll i=1; i<=n; i++){
        cout << "? " << i << " " << B1 << endl;
        ll tmp; cin >> tmp;
        A.pb(tmp);
    }

    ll A1 = 0;
    rep(i, n){
        if(A[i]==1){
            A1 = i+1;
            break;
        }
    }

    //質問3回目
    vector<ll> B;
    for(ll j=1; j<=n; j++){
        cout << "? " << A1 << " " << j << endl;
        ll tmp; cin >> tmp;
        B.pb(tmp);
    }

    cout << "! ";
    rep(i, n) cout << A[i] << " ";
    rep(i, n) cout << B[i] << " ";
    cout << endl;
}
0