QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87320#5687. 速战速决smallTarjan#WA 438ms20752kbC++141.7kb2023-03-12 15:14:482023-03-12 15:14:49

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:14:49]
  • Judged
  • Verdict: WA
  • Time: 438ms
  • Memory: 20752kb
  • [2023-03-12 15:14:48]
  • 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--;
            if(it -> first == 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];
			}
            x = it -> first;
            printf("%d ", x);
            mp[x]--, zhan[++top] = x, ok[x] = 1;
            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

5
1 2 4 4 3
*/

详细

Test #1:

score: 100
Accepted
time: 328ms
memory: 18452kb

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 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...

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 438ms
memory: 20212kb

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 289892 289891 289890 289889 289888 289887 289886 289885 289884 289883 289882 289881 289880 289879 289878 289877 289876 289875 289874 289873 289872 289871 289870 289869 289868 289867 289866 289865 289864 289863 289862 289861 289860 289859 289858 289857 289856 289855 289854 289853 289852...

result:

ok Correct.

Test #3:

score: -100
Wrong Answer
time: 418ms
memory: 20752kb

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
292190 292189 292189 292188 292188 292185 292185 292183 292183 292181 292181 292180 292180 292179 292179 292177 292177 292175 292175 292172 292172 292171 292171 292167 292167 292166 292166 292165 292165 292164 292164 292162 292162 292157 292157 292156 292156 292154 292154 292152 292152 292151...

result:

FAIL card does not exist