結果

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

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn=20005;
ll p[maxn+5],q[maxn+5],deg[maxn+5],pos[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;
}
void del(ll val){
    if(pos[val]==-1)return;
    ll last=s.back();
    ll idx=pos[val];
    s[idx]=last;
    pos[last]=idx;
    s.pop_back();
    pos[val]=-1;
}
int main(){
    ll t,n,i,j,k,zc,zc1,zc2,idx1,idxN,cur,cnt;
    srand(time(0));
    scanf("%lld",&t);
    while(t--){
        scanf("%lld",&n);
        s.clear();
        for(i=1;i<=n;i++)s.push_back(i),pos[i]=i-1,deg[i]=0,p[i]=0,q[i]=0;
        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){
                del(k);
            }
            else{
                zc=rand()%n+1;
                while(zc==zc1 or zc==zc2)zc=rand()%n+1;
                k=ask(zc1,zc);
                if(k==-1)del(zc1);
                else del(k);
            }
        }
        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]++;
            }
        }
        cur=-1;
        for(i=1;i<=n;i++){
            if(i!=idx1 and deg[i]==0){
                cur=i;
                break;
            }
        }
        cnt=2;
        while(cur!=0){
            q[cur]=cnt++;
            cur=p[cur];
        }
        printf("2");
        for(i=1;i<=n;i++)printf(" %lld",q[i]);
        printf("\n");
        fflush(stdout);
    }
    return 0;
}
0