QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281725 | #5687. 速战速决 | iorit | WA | 62ms | 18784kb | C++14 | 2.5kb | 2023-12-10 16:46:49 | 2023-12-10 16:46:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
namespace IO {
#if ONLINE_JUDGE
#define getc() (IS == IT && (IT = (IS = ibuf) + fread(ibuf, 1, IL, stdin), IS == IT) ? EOF : *IS++)
#else
#define getc() getchar()
#endif
const int IL = 1 << 21, OL = 1 << 21;
int olen = 0;
char ibuf[IL], *IS = ibuf, *IT = ibuf, obuf[OL];
inline int read() {
register char ch = getc(); register int x = 0, f = 1;
while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
return x * f;
}
inline double readdb() {
register char ch = getc(); register double x = 0, f = 1;
while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
if(ch == '.') {
register double b = 0.1;
ch = getc();
while(isdigit(ch)) x += (ch - 48) * b, b *= 0.1, ch = getc();
}
return x * f;
}
inline int readstr(char *s) {
register char ch = getc(); register int len = 0;
while(!isalpha(ch)) ch = getc();
while(isalpha(ch)) s[++len] = ch, ch = getc();
return len;
}
inline void flush() { fwrite(obuf, 1, olen, stdout); olen = 0; }
inline void putc(register char ch) { obuf[olen++] = ch; }
template<class T>
inline void write(register T x) {
if(x < 0) obuf[olen++] = '-', x = -x;
if(x > 9) write(x / 10);
obuf[olen++] = x % 10 + 48;
}
} using namespace IO;
const int N = 3e5 + 10;
int n, a[N], cnt[N];
set<int> s1, s2;
bool vis[N];
int main() {
n = read();
for(int i = 1; i <= n; i++)
cnt[i] = 2;
for(int i = 1; i <= n; i++)
a[i] = read(), cnt[a[i]]--;
if(n == 1) {
puts("-1");
return 0;
}
bool flg = 0;
for(int i = 1; i <= n; i++) {
if(cnt[i] != 1) flg = 1;
if(cnt[i] == 1) s1.insert(i);
if(cnt[i] == 2) s2.insert(i);
}
if(!flg) {
printf("%d\n", n + 2);
printf("%d ", a[n]);
for(int i = 1; i <= n - 1; i++)
printf("%d ", a[i]);
printf("%d ", a[1]);
printf("%d ", a[1]);
return 0;
}
int x = *s2.begin();
printf("%d\n", n);
printf("%d ", x);
int top = 1;
for(int i = 1; i < n; i++) {
vis[a[i]] = 1;
if(!cnt[a[i + 1]] && vis[a[i + 1]]) {
cnt[a[i + 1]] = 2;
printf("%d ", x);
x = a[i + 1];
if(i + 1 != n)printf("%d ", *s2.begin());
s2.erase(s2.begin());
i++;
continue;
}
if(cnt[a[i]] == 1) {
printf("%d ", a[i]);
s2.insert(a[i]);
}
else {
printf("%d ", *s2.begin());
s2.erase(s2.begin());
continue;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 62ms
memory: 18784kb
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 98406 111454 30346 4 7 107964 8 10 16843 182333 18 195166 188257 172666 20 157060 237654 26 145065 57507 152240 187931 5706 29 214174 30 38 40 61529 85258 74139 42 181186 223348 222711 19237 44 20487 45 139234 48 51 242997 52 59 218467 62 67 68 50360 142553 69 1...
result:
FAIL card does not exist