結果

問題 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,132 ms
コンパイル使用メモリ 207,044 KB
実行使用メモリ 25,448 KB
平均クエリ数 953.83
最終ジャッジ日時 2024-07-26 17:18:50
合計ジャッジ時間 5,271 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,556 KB
testcase_01 AC 22 ms
24,836 KB
testcase_02 AC 22 ms
25,220 KB
testcase_03 AC 22 ms
25,220 KB
testcase_04 AC 21 ms
24,580 KB
testcase_05 WA -
testcase_06 AC 22 ms
24,964 KB
testcase_07 AC 22 ms
24,808 KB
testcase_08 AC 21 ms
25,208 KB
testcase_09 AC 22 ms
24,964 KB
testcase_10 AC 20 ms
24,836 KB
testcase_11 AC 22 ms
25,448 KB
testcase_12 AC 21 ms
24,964 KB
testcase_13 AC 21 ms
24,580 KB
testcase_14 AC 21 ms
24,836 KB
testcase_15 AC 26 ms
24,812 KB
testcase_16 AC 28 ms
25,196 KB
testcase_17 AC 30 ms
24,812 KB
testcase_18 AC 83 ms
24,964 KB
testcase_19 AC 67 ms
24,836 KB
testcase_20 AC 87 ms
25,220 KB
testcase_21 AC 77 ms
24,836 KB
testcase_22 AC 70 ms
25,220 KB
testcase_23 AC 103 ms
24,836 KB
testcase_24 AC 87 ms
25,220 KB
testcase_25 AC 106 ms
25,220 KB
testcase_26 AC 106 ms
25,196 KB
testcase_27 AC 105 ms
24,928 KB
testcase_28 AC 103 ms
25,196 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void solve()':
main.cpp:64:26: warning: 'p' may be used uninitialized [-Wmaybe-uninitialized]
   64 |                     B[i] = p;
main.cpp:23:9: note: 'p' was declared here
   23 |     int p;
      |         ^
main.cpp:45:5: warning: 'iA' may be used uninitialized [-Wmaybe-uninitialized]
   45 |     if(iA != 0){
      |     ^~
main.cpp:32:9: note: 'iA' was declared here
   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