QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#281718#5687. 速战速决iorit#WA 35ms22188kbC++143.3kb2023-12-10 16:36:402023-12-10 16:36:40

Judging History

This is the latest submission verdict.

  • [2023-12-10 16:36:40]
  • Judged
  • Verdict: WA
  • Time: 35ms
  • Memory: 22188kb
  • [2023-12-10 16:36:40]
  • Submitted

answer

//#pragma GCC target("avx,avx2")
//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>

#define int long long
#define mem(x,y)memset(x,y,sizeof(x))
#define rep(i,l,r)for(int i = l;i <= r;i ++)
#define dep(i,r,l)for(int i = r;i >= l;i --)
#define tov(i)for(int i = head[x];i;i = e[i].nxt)
#define pb push_back
#define pi pair <int,int> 

using namespace std;

int read(){
    int s = 0,w = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-')w = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9')s = s * 10 + ch - '0',ch = getchar();
    return s * w;
}

namespace Tem{
    const int mod = 0;//Notice Here!!!!!!!!!!
    int fac[1000010],ifac[1000010];

    inline int gcd(int a, int b){
        int az = __builtin_ctz(a);
        int bz = __builtin_ctz(b);
        int z = az > bz ? bz : az;
        int diff;
        b >>= bz;
        while(a){
            a >>= az;
            diff = b - a;
            az = __builtin_ctz(diff);
            if(a < b)b = a;
            a = diff < 0 ? -diff : diff;
        }
        return b << z;
    }

    inline int poww(int x,int y,int MOD = mod){
        int s = 1;
        for(;y;x = x * x % MOD,y >>= 1)if(y & 1)s = s * x % MOD;
        return s;
    }

    void initfac(int n,int MOD = mod){
        fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
        rep(i,2,n)fac[i] = fac[i - 1] * i % MOD;
        ifac[n] = poww(fac[n],MOD - 2,MOD);
        dep(i,n - 1,2)ifac[i] = ifac[i + 1] * (i + 1)% MOD;
    }

    inline int inv(int x,int MOD = mod){return poww(x,MOD - 2)% MOD;}

    inline int C(int x,int y,int MOD = mod){return fac[x] * ifac[y] % MOD * ifac[x - y] % MOD;}

    void Add(int &x,int y){x = x + y >= mod ? x + y - mod : x + y;}
    void Dec(int &x,int y){x = x - y < 0 ? x - y + mod : x - y;}
    void Mul(int &x,int y){x = x * y % mod;}
}using namespace Tem;

int n;
int a[1000010];
int cnt[300010];
bool bk[300010];
int tot;
int to[300010];
int b[1000010];
int cnt2[300010];

queue <int> q;

signed main(){
    cin>>n;
    rep(i,1,n)a[i] = read();
    if(n == 1){
        puts("-1");
        return 0;
    }
    rep(i,1,n){
        cnt[a[i]] ++;
        if(cnt[a[i]] == 2)tot ++;
    }
    if(!tot){
        cout<<n + 2<<endl;
        cout<<a[n]<<" ";
        rep(i,1,n - 1)printf("%lld ",a[i]);
        cout<<a[1]<<" "<<a[1];
        return 0;
    }
    int kv = 0;
    rep(i,1,n){
        if(cnt[i] == 1)b[++ kv] = i;
        if(cnt[i] == 0)b[++ kv] = i,b[++ kv] = i;
    }
    rep(i,1,n)if(cnt[a[i]] == 2)bk[i] = 1;
    rep(i,1,n)cnt2[b[i]] ++;
    rep(i,1,n)if(cnt2[i] == 2)q.push(i);
    cout<<n<<endl;
    mem(to,-1);
    int lst;
    lst = q.front();
    q.pop();
    cout<<lst<<" ";
    rep(i,1,n - 1){
        int v = a[i];
        int nxt = a[i + 1];
        if(cnt[v] == 2 && to[v] == -1){
            to[v] = 1;
            if(cnt[nxt] == 2 && to[nxt] == -1){
                int now = q.front();
                q.pop();
                printf("%lld ",now);
            }
            else {
                printf("%lld ",lst);
                i ++;
                q.push(lst);
                int now = q.front();
                q.pop();
                if(i < n - 1)printf("%lld ",now);
                lst = now;
            }
        }
        else printf("%lld ",a[i]);
    }
}

详细

Test #1:

score: 100
Accepted
time: 33ms
memory: 20108kb

input:

249665
195633 37425 205189 128330 159707 98406 111454 30346 158516 121742 107964 50039 201395 16843 182333 60177 195166 188257 172666 71779 157060 237654 123572 145065 57507 152240 187931 5706 191077 214174 70950 71272 172767 61529 85258 74139 44633 181186 223348 222711 19237 239887 20487 84130 1392...

output:

249665
2 195633 37425 205189 128330 2 4 111454 30346 7 4 8 10 8 18 182333 18 20 188257 172666 20 26 237654 26 29 57507 152240 187931 5706 29 30 38 40 30 42 85258 74139 42 44 223348 222711 19237 44 45 45 48 51 48 52 59 52 62 67 68 62 69 142553 69 73 82591 83845 62942 73 75 95070 79 80 75 81 205096 85...

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 21ms
memory: 22188kb

input:

289892
233602 170432 186700 23520 1359 74354 61778 97676 141808 279091 86618 107162 187289 270874 5771 92359 256248 59758 201034 111974 157736 29506 210946 178606 275526 119662 142498 119239 245490 9443 240901 72345 207797 759 91770 131534 189757 72201 5921 152878 237072 146758 101282 50083 61126 26...

output:

289892
245154 233602 170432 186700 23520 1359 74354 61778 97676 141808 279091 86618 107162 187289 270874 5771 92359 256248 59758 201034 111974 157736 29506 210946 178606 275526 119662 142498 119239 245490 9443 240901 72345 207797 759 91770 131534 189757 72201 5921 152878 237072 146758 101282 50083 6...

result:

ok Correct.

Test #3:

score: 0
Accepted
time: 35ms
memory: 20656kb

input:

292190
145417 283887 12115 4326 45188 164129 14638 269369 233283 201793 241021 17606 90840 34917 16328 180328 261955 172583 181417 7942 223673 262641 28684 237776 243658 74833 205577 122527 28528 249819 73252 270152 117871 31565 204148 216504 192924 29203 143059 154759 104752 69112 166848 232567 962...

output:

292190
2 3 5 7 8 9 10 13 15 16 17 20 21 23 24 25 26 30 31 34 37 38 39 40 44 45 47 52 53 55 60 61 63 66 69 70 71 72 78 81 83 85 89 91 95 97 98 100 102 105 106 109 110 113 117 118 122 123 125 126 127 130 132 133 134 135 136 143 144 147 148 149 150 151 153 155 159 160 161 162 163 164 169 171 173 175 17...

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 30ms
memory: 20864kb

input:

289638
179249 177210 122624 75928 106218 13899 249362 245081 212282 3125 52160 49231 77788 143892 158982 277667 242837 199352 19097 201259 164534 261237 201825 180668 58106 141543 286211 251784 6410 112507 51157 93955 107491 250456 58875 36203 234469 45239 283807 106103 197348 238937 162203 287869 1...

output:

289638
1 2 3 5 6 8 11 13 15 17 20 23 25 26 27 29 30 31 34 35 36 38 39 42 47 48 50 51 52 53 54 56 57 58 59 60 62 63 64 67 68 69 70 74 76 77 78 82 84 85 86 88 90 91 93 94 95 98 99 102 103 105 106 107 108 109 110 111 112 113 116 120 122 125 128 130 132 134 135 138 140 141 145 146 149 150 151 157 159 16...

result:

ok Correct.

Test #5:

score: 0
Accepted
time: 22ms
memory: 20392kb

input:

261175
113751 113751 247389 247389 106728 106728 249714 249714 128388 128388 216271 216271 163974 163974 245217 245217 246248 246248 51361 51361 176423 176423 19217 19217 197524 197524 251874 251874 112335 112335 160213 160213 60037 60037 250967 250967 187608 187608 214950 214950 208541 208541 25669...

output:

261175
2 2 3 3 4 4 5 5 8 8 12 12 13 13 15 15 19 19 21 21 22 22 24 24 26 26 29 29 31 31 32 32 36 36 40 40 42 42 43 43 49 49 55 55 58 58 60 60 64 64 65 65 66 66 67 67 68 68 69 69 70 70 71 71 72 72 74 74 75 75 76 76 77 77 78 78 80 80 81 81 82 82 83 83 84 84 85 86 87 85 88 88 89 89 91 91 92 92 94 94 95 ...

result:

ok Correct.

Test #6:

score: 0
Accepted
time: 13ms
memory: 20232kb

input:

235687
63799 71109 20584 139647 35537 3706 218536 48564 213438 186010 156300 113267 147774 194058 51317 150706 90938 10941 6713 175756 29369 170762 71917 56104 19923 152417 157391 24269 651 205117 57134 130459 204707 14596 183539 32848 219225 58014 162840 153464 135755 16381 91308 77955 176504 66784...

output:

235687
200863 63799 71109 20584 139647 35537 3706 218536 48564 213438 186010 156300 113267 147774 194058 51317 150706 90938 10941 6713 175756 29369 170762 71917 56104 19923 152417 157391 24269 651 205117 57134 130459 204707 14596 183539 32848 219225 58014 162840 153464 135755 16381 91308 77955 17650...

result:

ok Correct.

Test #7:

score: 0
Accepted
time: 35ms
memory: 21400kb

input:

286065
210717 98065 272406 215134 231139 267285 38811 254951 247150 55368 273010 247371 85937 256408 11755 96321 53159 66358 234133 68621 160218 285535 185357 247070 261590 43071 54158 13202 281537 21836 3621 234524 109158 188905 62618 144070 211133 129125 262129 85892 198535 174556 2297 62475 19242...

output:

286065
21 210717 98065 25 36 45 48 21 55 55 56 273010 247371 56 59 11755 96321 63 65 59 66 160218 285535 66 67 68 69 71 67 78 78 79 234524 79 81 62618 81 85 129125 85 91 198535 174556 2297 62475 192421 92 91 94 99 94 104 104 110 185287 148150 120490 207084 112 115 116 118 110 121 130 121 132 132 133...

result:

ok Correct.

Test #8:

score: 0
Accepted
time: 28ms
memory: 20448kb

input:

296716
132049 132049 256044 256044 110447 110447 263700 263700 36769 36769 171894 171894 60205 60205 227616 227616 286799 286799 281611 281611 124684 124684 284840 284840 213378 213378 140028 140028 7425 7425 154415 154415 71482 71482 156517 156517 295706 295706 142794 142794 10192 10192 132364 1323...

output:

296716
1 1 2 2 3 3 4 4 6 6 10 10 11 11 12 12 13 13 17 17 19 19 24 24 25 25 26 26 35 35 37 37 40 40 42 42 43 43 46 46 47 47 49 49 50 50 54 54 56 56 58 58 60 60 65 65 67 67 68 68 69 69 71 71 74 74 75 75 76 76 77 77 79 79 86 86 87 87 88 88 89 89 90 90 96 96 97 97 99 99 102 102 103 103 105 105 106 106 1...

result:

ok Correct.

Test #9:

score: 0
Accepted
time: 1ms
memory: 7932kb

input:

1
1

output:

-1

result:

ok Correct.

Test #10:

score: 0
Accepted
time: 0ms
memory: 14252kb

input:

2
1 1

output:

2
2 2 

result:

ok Correct.

Test #11:

score: 0
Accepted
time: 2ms
memory: 14136kb

input:

4
1 1 4 2

output:

4
3 3 3 4 

result:

ok Correct.

Test #12:

score: -100
Wrong Answer
time: 0ms
memory: 12532kb

input:

5
2 4 3 4 3

output:

5
1 2 5 1 

result:

wrong output format Unexpected end of file - int32 expected