結果

問題 No.2577 Simple Permutation Guess
ユーザー tko919tko919
提出日時 2023-12-05 01:03:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
QLE  
実行時間 -
コード長 3,091 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 211,416 KB
実行使用メモリ 24,012 KB
平均クエリ数 248.94
最終ジャッジ日時 2023-12-05 01:03:57
合計ジャッジ時間 24,638 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,000 KB
testcase_01 AC 241 ms
24,000 KB
testcase_02 AC 56 ms
24,000 KB
testcase_03 AC 31 ms
24,000 KB
testcase_04 AC 82 ms
24,000 KB
testcase_05 AC 112 ms
24,000 KB
testcase_06 AC 361 ms
24,000 KB
testcase_07 AC 342 ms
24,000 KB
testcase_08 AC 345 ms
24,000 KB
testcase_09 AC 340 ms
24,000 KB
testcase_10 AC 336 ms
24,000 KB
testcase_11 AC 25 ms
24,000 KB
testcase_12 AC 24 ms
24,000 KB
testcase_13 AC 27 ms
24,000 KB
testcase_14 AC 25 ms
24,000 KB
testcase_15 AC 24 ms
24,000 KB
testcase_16 AC 24 ms
24,000 KB
testcase_17 AC 23 ms
24,000 KB
testcase_18 AC 22 ms
24,000 KB
testcase_19 AC 23 ms
24,000 KB
testcase_20 QLE -
testcase_21 QLE -
testcase_22 AC 24 ms
24,012 KB
testcase_23 AC 24 ms
24,012 KB
testcase_24 AC 24 ms
24,012 KB
testcase_25 AC 24 ms
24,012 KB
testcase_26 AC 25 ms
24,012 KB
testcase_27 AC 23 ms
24,012 KB
testcase_28 AC 23 ms
24,012 KB
testcase_29 AC 23 ms
24,012 KB
testcase_30 AC 24 ms
24,012 KB
testcase_31 AC 23 ms
24,000 KB
testcase_32 AC 23 ms
24,000 KB
testcase_33 AC 24 ms
24,000 KB
testcase_34 AC 23 ms
24,000 KB
testcase_35 AC 22 ms
24,000 KB
testcase_36 AC 23 ms
24,000 KB
testcase_37 AC 23 ms
24,000 KB
testcase_38 AC 23 ms
24,000 KB
testcase_39 AC 23 ms
24,000 KB
testcase_40 AC 24 ms
24,000 KB
testcase_41 AC 24 ms
24,000 KB
testcase_42 AC 24 ms
24,000 KB
testcase_43 AC 23 ms
24,000 KB
testcase_44 AC 24 ms
24,000 KB
testcase_45 AC 23 ms
24,000 KB
testcase_46 AC 23 ms
24,000 KB
testcase_47 AC 23 ms
24,000 KB
testcase_48 AC 22 ms
24,000 KB
testcase_49 AC 24 ms
24,000 KB
testcase_50 AC 23 ms
24,000 KB
testcase_51 AC 23 ms
24,000 KB
testcase_52 AC 23 ms
24,000 KB
testcase_53 AC 23 ms
24,000 KB
testcase_54 AC 23 ms
24,000 KB
testcase_55 AC 23 ms
24,000 KB
testcase_56 AC 23 ms
24,000 KB
testcase_57 AC 22 ms
24,000 KB
testcase_58 AC 25 ms
24,000 KB
testcase_59 AC 23 ms
24,000 KB
testcase_60 AC 24 ms
24,000 KB
testcase_61 AC 23 ms
24,000 KB
testcase_62 QLE -
testcase_63 QLE -
testcase_64 AC 22 ms
24,012 KB
testcase_65 AC 23 ms
24,012 KB
testcase_66 AC 25 ms
24,012 KB
testcase_67 AC 23 ms
24,012 KB
testcase_68 AC 43 ms
24,012 KB
testcase_69 AC 23 ms
24,012 KB
testcase_70 AC 24 ms
24,012 KB
testcase_71 AC 23 ms
24,012 KB
testcase_72 AC 24 ms
24,012 KB
testcase_73 AC 23 ms
24,000 KB
testcase_74 AC 25 ms
24,000 KB
testcase_75 AC 28 ms
24,000 KB
testcase_76 AC 26 ms
24,000 KB
testcase_77 AC 25 ms
24,000 KB
testcase_78 AC 25 ms
24,000 KB
testcase_79 AC 25 ms
24,000 KB
testcase_80 AC 26 ms
24,000 KB
testcase_81 AC 26 ms
24,000 KB
testcase_82 AC 26 ms
24,000 KB
testcase_83 AC 27 ms
24,000 KB
testcase_84 AC 26 ms
24,000 KB
testcase_85 AC 27 ms
24,000 KB
testcase_86 AC 27 ms
24,000 KB
testcase_87 AC 26 ms
24,012 KB
testcase_88 AC 26 ms
24,012 KB
testcase_89 AC 25 ms
24,012 KB
testcase_90 AC 26 ms
24,012 KB
testcase_91 AC 25 ms
24,012 KB
testcase_92 AC 260 ms
24,012 KB
testcase_93 AC 222 ms
24,012 KB
testcase_94 AC 205 ms
24,012 KB
testcase_95 AC 316 ms
24,012 KB
testcase_96 AC 320 ms
24,012 KB
testcase_97 AC 297 ms
24,012 KB
testcase_98 AC 285 ms
24,012 KB
testcase_99 AC 307 ms
24,012 KB
testcase_100 AC 222 ms
24,012 KB
testcase_101 AC 288 ms
24,012 KB
evil_1_rnd_1.txt AC 811 ms
24,012 KB
evil_1_rnd_2.txt AC 826 ms
24,012 KB
evil_2_big_1.txt AC 1,151 ms
24,012 KB
evil_2_big_2.txt AC 1,135 ms
24,012 KB
evil_2_big_3.txt AC 1,142 ms
24,012 KB
evil_3_sorted_1.txt AC 472 ms
24,012 KB
evil_4_sorted_rev_1.txt AC 331 ms
24,012 KB
evil_4_sorted_rev_2.txt AC 536 ms
24,012 KB
evil_400_sorted.txt AC 1,015 ms
24,012 KB
evil_400_sorted_rev.txt AC 1,032 ms
24,012 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[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