結果

問題 No.3400 Nana's Plus Permutation Game (7 + 7) ÷ 7
コンテスト
ユーザー Mike scarf
提出日時 2025-12-12 16:11:43
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
TLE  
実行時間 -
コード長 1,760 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,187 ms
コンパイル使用メモリ 279,112 KB
実行使用メモリ 104,256 KB
最終ジャッジ日時 2025-12-12 16:11:55
合計ジャッジ時間 11,325 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 76
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘long long int ask(long long int, long long int)’:
main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |     scanf("%lld",&res);
      |     ~~~~~^~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |     scanf("%lld",&t);
      |     ~~~~~^~~~~~~~~~~
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf("%lld",&n);
      |         ~~~~~^~~~~~~~~~~

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn=20005;
ll q[maxn+5],p[maxn+5],deg[maxn+5];
bool isc[maxn+5];
vector<ll> s;
ll ask(ll i,ll j){
    printf("1 %lld %lld\n",i,j);
    fflush(stdout);
    ll res;
    scanf("%lld",&res);
    return res;
}
int main(){
    ll t,n,i,j,k,zc1,zc2,idx1,idxN,dq,cnt;
    srand(time(0));
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        for(i=1;i<=n;i++)isc[i]=false,deg[i]=0,p[i]=0;
        s.clear();
        for(i=1;i<=n;i++)s.push_back(i);
        while(s.size()>1){
            zc1=s[rand()%s.size()];
            zc2=rand()%n+1;
            while(zc1==zc2)zc2=rand()%n+1;
            k=ask(zc1,zc2);
            if(k!=-1){
                if(!isc[k]){
                    isc[k]=true;
                    for(i=0;i<s.size();i++){
                        if(s[i]==k){
                            s[i]=s.back();
                            s.pop_back();
                            break;
                        }
                    }
                }
            }
        }
        idx1=s[0];
        q[idx1]=1;
        idxN=-1;
        for(i=1;i<=n;i++){
            if(i==idx1)continue;
            k=ask(idx1,i);
            if(k==-1)idxN=i;
            else{
                p[i]=k;
                deg[k]++;
            }
        }
        dq=-1;
        for(i=1;i<=n;i++){
            if(i!=idx1 and deg[i]==0){
                dq=i;
                break;
            }
        }
        cnt=2;
        while(dq!=idxN and dq!=0){
            q[dq]=cnt++;
            dq=p[dq];
        }
        if(idxN!=-1)q[idxN]=n;
        printf("2");
        for(i=1;i<=n;i++)printf(" %lld",q[i]);
        printf("\n");
        fflush(stdout);
    }
    return 0;
}
0