結果

問題 No.2496 LCM between Permutations
ユーザー bortikbortik
提出日時 2023-10-06 23:40:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,274 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 204,276 KB
実行使用メモリ 24,420 KB
平均クエリ数 953.83
最終ジャッジ日時 2023-10-06 23:40:37
合計ジャッジ時間 6,036 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
24,240 KB
testcase_01 AC 26 ms
23,832 KB
testcase_02 AC 26 ms
23,652 KB
testcase_03 AC 26 ms
24,036 KB
testcase_04 AC 26 ms
23,964 KB
testcase_05 WA -
testcase_06 AC 26 ms
23,244 KB
testcase_07 AC 27 ms
23,412 KB
testcase_08 AC 27 ms
24,036 KB
testcase_09 AC 26 ms
23,400 KB
testcase_10 AC 27 ms
23,652 KB
testcase_11 AC 28 ms
24,036 KB
testcase_12 AC 26 ms
23,640 KB
testcase_13 AC 27 ms
24,024 KB
testcase_14 AC 27 ms
23,664 KB
testcase_15 AC 33 ms
23,832 KB
testcase_16 AC 34 ms
24,420 KB
testcase_17 AC 36 ms
24,024 KB
testcase_18 AC 91 ms
23,652 KB
testcase_19 AC 71 ms
23,832 KB
testcase_20 AC 95 ms
24,276 KB
testcase_21 AC 86 ms
23,640 KB
testcase_22 AC 80 ms
23,832 KB
testcase_23 AC 106 ms
23,544 KB
testcase_24 AC 92 ms
24,336 KB
testcase_25 AC 117 ms
23,520 KB
testcase_26 AC 113 ms
23,676 KB
testcase_27 AC 114 ms
23,388 KB
testcase_28 AC 114 ms
23,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:64:26: 警告: ‘p’ may be used uninitialized [-Wmaybe-uninitialized]
   64 |                     B[i] = p;
main.cpp:23:9: 備考: ‘p’ はここで定義されています
   23 |     int p;
      |         ^
main.cpp:45:5: 警告: ‘iA’ may be used uninitialized [-Wmaybe-uninitialized]
   45 |     if(iA != 0){
      |     ^~
main.cpp:32:9: 備考: ‘iA’ はここで定義されています
   32 |     int iA, iB = 0;
      |         ^~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, n, a) for (int i = (int)(n); i >= (int)(a); i--)

bool isprime(int num){
    if(num < 2) return false;
    for(int i = 2; i <= int(sqrt(num)); i++){
        if( num % i == 0) return false;
    }
    return true;
}

void solve(){
    int n; cin >> n;
    if(n == 1){
        cout << "! 1 1" << endl;
        return;
    }
    int p;
    rrep(i, n, 1){
        if(isprime(i)){
            p = i;
            break;
        }
    }
    int prev = 1;
    int s = 1;
    int iA, iB = 0;
    rep(i,1,n+1){
        cout << "? " << i << " " << 2 << endl;
        int cur; cin >> cur;
        if(cur % p == 0 && prev % p != 0){
            iA = i;
        } else if(prev % p == 0 && cur % p == 0){
            iB = i;
            iA = 0;
        }
        prev = cur;
    }
    vector<int> A(n+1, 0), B(n+1, 0);
    if(iA != 0){
        int c = 0;
        A[iA] = p;
        rep(i,1,n+1){
            cout << "? " << iA << " " << i << endl;
            int cur; cin >> cur;
            B[i] = cur / p;
            if(cur == p){
                if(c == 0){
                    cout << "? " << (iA)%n + 1 << " " << i << endl;
                    cin >> cur;
                    if(cur % p == 0){
                        c = 1;
                        B[i] = p;
                        iB = i;
                    } else {
                        c = 2;
                    }
                } else if(c == 2){
                    B[i] = p;
                    iB = i;
                    c = 1;
                }
                
            }
        }

        rep(i,1,iA){
            cout << "? " << i << " " << iB << endl;
            int cur; cin >> cur;
            A[i] = cur / p;
        }
        rep(i,iA+1,n+1){
            cout << "? " << i << " " << iB << endl;
            int cur; cin >> cur;
            A[i] = cur / p;
        }

    } else {
        int c = 0;
        B[iB] = p;
        rep(i,1,n+1){
            cout << "? " << i << " " << iB << endl;
            int cur; cin >> cur;
            A[i] = cur / p;
            if(cur == p){
                if(c == 0){
                    cout << "? " << i << " " << (iB)%n + 1 << endl;
                    cin >> cur;
                    if(cur % p == 0){
                        c = 1;
                        A[i] = p;
                        iA = i;
                    } else {
                        c = 2;
                    }
                } else if(c == 2){
                    A[i] = p;
                    iA = i;
                    c = 1;
                }
                
            }
        }

        rep(i,1,iB){
            cout << "? " << iA << " " << i << endl;
            int cur; cin >> cur;
            B[i] = cur / p;
        }
        rep(i,iB+1,n+1){
            cout << "? " << iA << " " << i << endl;
            int cur; cin >> cur;
            B[i] = cur / p;
        }
    }

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

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    rep(i,0,t) solve();

    return 0;
}
0