QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281720#5687. 速战速决iorit#WA 33ms21044kbC++143.3kb2023-12-10 16:39:032023-12-10 16:39:03

Judging History

This is the latest submission verdict.

  • [2023-12-10 16:39:03]
  • Judged
  • Verdict: WA
  • Time: 33ms
  • Memory: 21044kb
  • [2023-12-10 16:39:03]
  • 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){
        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]);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 33ms
memory: 21044kb

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:

wrong output format Extra information in the output file