QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87314#5687. 速战速决smallTarjan#WA 382ms18252kbC++141.5kb2023-03-12 15:00:572023-03-12 15:00:59

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-12 15:00:59]
  • Judged
  • Verdict: WA
  • Time: 382ms
  • Memory: 18252kb
  • [2023-03-12 15:00:57]
  • Submitted

answer

#include <cstdio>
#include <map>
using namespace std;
#define re int 
#define maxn 300005

int n;
int a[maxn];
int vs[maxn];
int ok[maxn];

int top;
int zhan[maxn];

map<int, int> mp;

int main()
{
    scanf("%d", &n);
    re i;
    for(i = 1;i <= n;i++) vs[i] = 2;
    for(i = 1;i <= n;i++) scanf("%d", &a[i]), vs[a[i]]--;
    if(n == 1){
        printf("-1\n");
        return 0;
    }
    int f = 0;
    for(i = 1;i <= n;i++){
        if(vs[i]) mp[i] = vs[i];
        if(vs[i] == 2) f = i;
    }
    if(!f) {
        printf("-1\n");
        return 0;
    }
    printf("%d\n", n);
    printf("%d ", f);
    map<int, int>::iterator it;
    zhan[++top] = f, ok[f] = 1, mp[f]--;
    int x;
    for(i = 1;i < n;i++){
        ok[a[i]] = 1, zhan[++top] = a[i];
        if(ok[a[i + 1]]){
            printf("%d ", f);
            while(zhan[top] != f) {
                mp[zhan[top]]++, ok[zhan[top]] = 0, top--;
            }
            mp[zhan[top]]++, ok[zhan[top]] = 0, top--;
            f = a[i + 1];
        }
        else {
            it = mp.end();
            it--;
            while(it -> first == a[i + 1] || (it -> first == f && !mp[a[i + 1]])) it--;
            x = it -> first;
            //printf("?%d? ", mp[8]);
            printf("%d ", x);
            mp[x]--, zhan[++top] = x, ok[x] = 1;
            //printf("?%d?\n", mp[8]);
            if(mp[x] == 0) 
				mp.erase(x);
        }
    }
    return 0;
}
/*
3
1 3 3

1
1

5
1 2 3 4 4

8
1 2 2 3 4 5 3 1
*/

详细

Test #1:

score: 0
Wrong Answer
time: 382ms
memory: 18252kb

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
249660 249664 249663 249662 249661 249660 249659 249657 249656 249655 249654 249654 249653 249652 249652 249651 249649 249648 249648 249647 249645 249644 249644 249643 249642 249640 249640 249639 249637 249635 249634 249633 249632 249632 249631 249631 249629 249628 249628 249627 249626 249624...

result:

FAIL card does not exist