結果

問題 No.2577 Simple Permutation Guess
ユーザー tko919tko919
提出日時 2023-12-05 01:08:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 3,122 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 210,368 KB
実行使用メモリ 25,580 KB
平均クエリ数 248.89
最終ジャッジ日時 2024-09-26 23:50:41
合計ジャッジ時間 20,808 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
24,556 KB
testcase_01 AC 214 ms
24,812 KB
testcase_02 AC 49 ms
25,196 KB
testcase_03 AC 21 ms
24,556 KB
testcase_04 AC 72 ms
24,812 KB
testcase_05 AC 103 ms
25,196 KB
testcase_06 AC 289 ms
25,580 KB
testcase_07 AC 292 ms
24,556 KB
testcase_08 AC 297 ms
24,556 KB
testcase_09 AC 288 ms
25,196 KB
testcase_10 AC 289 ms
25,196 KB
testcase_11 AC 21 ms
24,556 KB
testcase_12 AC 20 ms
25,184 KB
testcase_13 AC 23 ms
24,812 KB
testcase_14 AC 22 ms
24,812 KB
testcase_15 AC 20 ms
24,812 KB
testcase_16 AC 21 ms
24,556 KB
testcase_17 AC 21 ms
24,556 KB
testcase_18 AC 21 ms
24,940 KB
testcase_19 AC 20 ms
25,196 KB
testcase_20 AC 20 ms
24,940 KB
testcase_21 AC 22 ms
25,196 KB
testcase_22 AC 22 ms
24,580 KB
testcase_23 AC 23 ms
24,452 KB
testcase_24 AC 22 ms
24,836 KB
testcase_25 AC 22 ms
25,220 KB
testcase_26 AC 21 ms
24,836 KB
testcase_27 AC 21 ms
24,836 KB
testcase_28 AC 21 ms
24,964 KB
testcase_29 AC 21 ms
25,208 KB
testcase_30 AC 21 ms
25,076 KB
testcase_31 AC 26 ms
25,196 KB
testcase_32 AC 22 ms
24,940 KB
testcase_33 AC 21 ms
24,556 KB
testcase_34 AC 20 ms
24,556 KB
testcase_35 AC 20 ms
25,452 KB
testcase_36 AC 21 ms
25,196 KB
testcase_37 AC 22 ms
25,220 KB
testcase_38 AC 20 ms
25,220 KB
testcase_39 AC 21 ms
24,964 KB
testcase_40 AC 21 ms
24,836 KB
testcase_41 AC 21 ms
24,836 KB
testcase_42 AC 21 ms
24,580 KB
testcase_43 AC 21 ms
24,580 KB
testcase_44 AC 21 ms
24,848 KB
testcase_45 AC 21 ms
25,220 KB
testcase_46 AC 21 ms
24,964 KB
testcase_47 AC 23 ms
25,220 KB
testcase_48 AC 21 ms
24,836 KB
testcase_49 AC 21 ms
24,964 KB
testcase_50 AC 22 ms
24,660 KB
testcase_51 AC 20 ms
24,836 KB
testcase_52 AC 20 ms
25,464 KB
testcase_53 AC 20 ms
24,824 KB
testcase_54 AC 21 ms
25,220 KB
testcase_55 AC 20 ms
25,220 KB
testcase_56 AC 21 ms
24,580 KB
testcase_57 AC 22 ms
24,836 KB
testcase_58 AC 20 ms
24,836 KB
testcase_59 AC 20 ms
25,220 KB
testcase_60 AC 19 ms
24,580 KB
testcase_61 AC 22 ms
24,964 KB
testcase_62 AC 21 ms
24,824 KB
testcase_63 AC 20 ms
24,836 KB
testcase_64 AC 20 ms
25,220 KB
testcase_65 AC 21 ms
25,220 KB
testcase_66 AC 21 ms
24,964 KB
testcase_67 AC 22 ms
25,220 KB
testcase_68 AC 21 ms
24,836 KB
testcase_69 AC 22 ms
25,220 KB
testcase_70 AC 21 ms
25,220 KB
testcase_71 AC 21 ms
25,220 KB
testcase_72 AC 20 ms
24,836 KB
testcase_73 AC 20 ms
25,052 KB
testcase_74 AC 22 ms
25,196 KB
testcase_75 AC 22 ms
25,196 KB
testcase_76 AC 22 ms
24,812 KB
testcase_77 AC 23 ms
24,800 KB
testcase_78 AC 23 ms
25,196 KB
testcase_79 AC 22 ms
25,196 KB
testcase_80 AC 23 ms
25,196 KB
testcase_81 AC 22 ms
24,812 KB
testcase_82 AC 22 ms
25,196 KB
testcase_83 AC 22 ms
24,556 KB
testcase_84 AC 22 ms
24,812 KB
testcase_85 AC 22 ms
24,940 KB
testcase_86 AC 22 ms
24,812 KB
testcase_87 AC 22 ms
24,940 KB
testcase_88 AC 22 ms
24,556 KB
testcase_89 AC 21 ms
25,196 KB
testcase_90 AC 22 ms
25,196 KB
testcase_91 AC 22 ms
24,812 KB
testcase_92 AC 224 ms
24,940 KB
testcase_93 AC 198 ms
25,196 KB
testcase_94 AC 182 ms
25,196 KB
testcase_95 AC 283 ms
24,812 KB
testcase_96 AC 288 ms
24,812 KB
testcase_97 AC 261 ms
25,580 KB
testcase_98 AC 251 ms
24,812 KB
testcase_99 AC 269 ms
25,196 KB
testcase_100 AC 194 ms
24,544 KB
testcase_101 AC 247 ms
24,556 KB
evil_1_rnd_1.txt AC 678 ms
24,556 KB
evil_1_rnd_2.txt AC 709 ms
25,324 KB
evil_2_big_1.txt AC 982 ms
24,940 KB
evil_2_big_2.txt AC 971 ms
25,196 KB
evil_2_big_3.txt AC 977 ms
24,812 KB
evil_3_sorted_1.txt AC 402 ms
25,464 KB
evil_4_sorted_rev_1.txt AC 293 ms
24,836 KB
evil_4_sorted_rev_2.txt AC 484 ms
24,836 KB
evil_400_sorted.txt AC 838 ms
25,208 KB
evil_400_sorted_rev.txt AC 890 ms
24,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "library/Template/template.hpp"
#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) sort(ALL(v)),(v).erase(unique(ALL(v)),(v).end())
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v,x) lower_bound(ALL(v),(x))-(v).begin()
#define UB(v,x) upper_bound(ALL(v),(x))-(v).begin()

using ll=long long int;
using ull=unsigned long long;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<typename T,typename U>T ceil(T x,U y){assert(y!=0); if(y<0)x=-x,y=-y; return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>T floor(T x,U y){assert(y!=0); if(y<0)x=-x,y=-y; return (x>0?x/y:(x-y+1)/y);}
template<typename T>int popcnt(T x){return __builtin_popcountll(x);}
template<typename T>int topbit(T x){return (x==0?-1:63-__builtin_clzll(x));}
template<typename T>int lowbit(T x){return (x==0?-1:__builtin_ctzll(x));}
#line 2 "sol.cpp"

int ask(vector<int>& a){
    cout<<"? ";
    rep(i,0,a.size())cout<<a[i]+1<<' ';
    cout<<endl;
    int B;
    cin>>B;
    return B;
}

void answer(vector<int>& a){
    cout<<"! ";
    rep(i,0,a.size())cout<<a[i]+1<<' ';
    cout<<endl;
}

int main(){
    int n;
    cin>>n;

    vector<int> L(n),R(n);
    iota(ALL(L),0);
    R=L;
    reverse(ALL(R));
    auto last=R;

    auto convert=[&](vector<int>& a)->vector<int>{
        vector<int> cnt(n),ret(n);
        rep(i,0,n){
            int sum=0;
            rep(j,0,a[i])sum+=cnt[j];
            ret[n-i-1]=a[i]-sum;
            cnt[a[i]]++;
        }
        return ret;
    };

    auto inverse=[&](vector<int>& a)->vector<int>{
        vector<int> ret(n),cnt(n);
        for(int i=n-1;i>=0;i--){
            int sum=0;
            rep(j,0,n)if(cnt[j]==0){
                sum++;
                if(sum==a[i]+1){
                    ret[n-1-i]=j;
                    break;
                }
            }
            cnt[ret[n-1-i]]++;
        }
        return ret;
    };

    for(;;){
        auto nxt=L;
        next_permutation(ALL(nxt));
        if(nxt==R)break;

        auto cL=convert(L);
        auto cR=convert(R);

        vector<int> cmid(n),odd(n),add(n);
        for(int i=n-1;i>=0;i--){
            cmid[i]=(cL[i]+cR[i])/2;
            odd[i]=(cL[i]+cR[i])&1;
        }
        for(int i=n-1;i>0;i--)if(odd[i]){
            if(i&1){
                if(i>1)add[i-2]+=i*(i-1)/2;
                else add[1]++;
            }
            else{
                add[i-1]+=i/2;
            }
        }
        int up=0;
        rep(i,0,n){
            cmid[i]+=add[i]+up;
            up=0;
            if(cmid[i]>i){
                up+=cmid[i]/(i+1);
                cmid[i]%=(i+1);
            }
        }
        assert(up==0);
        auto mid=inverse(cmid);
        
        if(ask(mid))L=mid;
        else R=mid;
    }
    if(R==last and ask(R))answer(R);
    else answer(L);
    return 0;
}
0