結果

問題 No.3737 Quiz Time
コンテスト
ユーザー karinohito
提出日時 2026-09-19 17:51:22
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 185 ms / 2,000 ms
+ 2µs
コード長 1,904 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,126 ms
コンパイル使用メモリ 339,268 KB
実行使用メモリ 6,528 KB
平均クエリ数 84.22
最終ジャッジ日時 2026-09-19 17:51:27
合計ジャッジ時間 5,041 ms
ジャッジサーバーID
(参考情報)
judge1_0 / <nil>
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll=long long;


int main(){
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);

    int N;
    cin>>N;

    vector<vector<int>> AN(N,vector<int>(N,0));
    for(int i=0;i<N-1;i++){
        cout<<"? "<<i+1<<" "<<i+1<<endl;
        cin>>AN[i][i];
        AN[i][i]--;
    }
    cout<<"? "<<1<<" "<<2<<endl;
    cin>>AN[0][1];
    AN[0][1]--;
    bool rev=0;
    if(AN[0][0]/N==AN[0][1]/N){
        rev=1;
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                swap(AN[i][j],AN[j][i]);
            }
        }
    }
    vector<bool> seen(N,0),seent(N,0);
    for(int i=0;i<N-1;i++){
        seen[AN[i][i]/N]=1;
        seent[AN[i][i]%N]=1;
    }

    for(int i=0;i<N;i++){
        if(!seen[i]){
            AN[N-1][N-1]+=i*N;
        }
        if(!seent[i]){
            AN[N-1][N-1]+=i;
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            AN[i][j]=AN[i][i]%N+(AN[j][j]/N)*N;
        }
    }
    if(rev){
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                swap(AN[i][j],AN[j][i]);
            }
        }
    }
    cout<<"!"<<endl;
    for(int i=0;i<N;i++)for(int j=0;j<N;j++){
        cout<<AN[i][j]+1<<" \n"[j==N-1];
    }
    cout<<flush;

    // vector<int> P(N*N);
    // for(int i=0;i<N*N;i++)P[i]=i;
    // do{
    //     bool OK=1;
    //     for(int i=0;i<N-1;i++){
    //         for(int j=0;j<N-1;j++){
    //             ll a=P[i*N+j]+P[(i+1)*N+j+1];
    //             ll b=P[i*N+j+1]+P[(i+1)*N+j];
    //             if(a!=b)OK=0;
    //         }
    //     }
    //     if(OK){
    //         for(int i=0;i<N;i++){
    //             for(int j=0;j<N;j++){
    //                 cout<<P[i*N+j]<<" \n"[j==N-1];
    //             }
    //         }
    //         cout<<endl;
    //     }
    // }while(next_permutation(P.begin(),P.end()));
}
0