QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#274113#4934. Forbidden Cardanhduc2701WA 12ms11144kbC++231.1kb2023-12-03 10:37:572023-12-03 10:37:58

Judging History

你现在查看的是最新测评结果

  • [2023-12-03 10:37:58]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:11144kb
  • [2023-12-03 10:37:57]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn=1e6+5;
int n,m;
int a[maxn];
int b[maxn];
int id[maxn];
int dp[maxn];
int ans[maxn];
signed main(){
    cin.tie(0),cout.tie(0)->sync_with_stdio(0);
    //freopen("input.inp","r",stdin);
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        cin >> a[i] >> b[i];
    }
    vector<int>play;
    int lose=0;
    for(int i=1;i<=3*n;i++){
        int p=(i-1)%n+1;
        if(id[a[p]]==0){
            id[a[p]]=i;
            play.pb(a[p]);
        }
        else if(id[b[p]]==0){
            id[b[p]]=i;
            play.pb(b[p]);
        }
        else{
            lose=p;
            break;
        }
    }
    ans[lose]=m-(int)play.size();
    for(int i=play.size()-1;i>=0;i--){
        int luot=i%n+1;
        if(play[i]==b[luot] || (play[i]==a[luot] && id[b[luot]]<luot)){
            dp[i]=luot;
        }
        else if(id[b[luot]]==0){
            dp[i]=lose;
        }
        else{
            dp[i]=dp[id[b[luot]]-1];
        }
        ans[dp[i]]++;
    }
    for(int i=1;i<=n;i++){
        cout << ans[i] << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9700kb

input:

3 6
1 2
2 4
4 2

output:

3
0
3

result:

ok 3 lines

Test #2:

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

input:

4 10
1 5
2 6
3 7
4 8

output:

4
2
2
2

result:

ok 4 lines

Test #3:

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

input:

1 2
1 2

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 12ms
memory: 11144kb

input:

69332 250102
51362 228823
206751 31351
181790 44202
186695 92215
172072 173179
86663 76959
42382 25827
204750 30001
42502 11959
201030 71886
227497 216114
164282 235028
178967 181951
125356 20611
169528 174071
50985 175562
63676 208400
189134 229462
49746 131529
180236 247427
29278 229589
30381 4412...

output:

180770
1
1
1
1
1
0
1
0
1
0
0
1
0
1
1
0
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
0
1
0
1
0
0
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
0
1
1
1
0
0
1
1
1
1
1
1
1
1
0
1
1
0
0
0
0
1
1
1
1
0
0
0
1
1
1
0
1
1
1
0
1
0
0
1
0
1
0
1
1
0
1
1
0
1
1
1
0
0
0
1
1
1
0
0
1
1
1
1
0
0...

result:

wrong answer 1st lines differ - expected: '197458', found: '180770'