QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#626012#9349. Exchanging GiftsThisTimeWA 221ms21876kbC++202.6kb2024-10-09 22:20:172024-10-09 22:20:18

Judging History

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

  • [2024-10-09 22:20:18]
  • 评测
  • 测评结果:WA
  • 用时:221ms
  • 内存:21876kb
  • [2024-10-09 22:20:17]
  • 提交

answer

#include<bits/stdc++.h>
#define deg(a) cout << #a << '=' << a << "\n"
#define all(a) a.begin(),a.end()
#define lowbit(x)  ((x)&(-x))
#define find1(x)  (__builtin_popcount(x))
#define pll pair<int,int>
// #define int long long   
#define endl '\n'
#define ff first
#define ss second
#define lc p<<1
#define rc p<<1|1
using namespace std;
using ll = long long;
const int N = 1e6+10;
const int M = 1e6+10;
const int mod1 = 998244353;
const int mod2 = 1e9+7;
const int inf = 0x3f3f3f3f3f3f3f;
const double eps = 1e-12;
int op[N];
std::vector<int> G[N];
int din[N] = {0};
int cnt[N] = {0};
std::vector<int> F[N];
int read()
{
    int k=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
    return k*f;
}
void solve(){
     int n;
     cin >> n;
     for(int i = 1 ; i <= n ; i++) {
         G[i].clear();
         F[i].clear();
         din[i] = 0;
         cnt[i] = 0;
     }
     for(int i = 1 ; i <= n ; i++) {
         op[i] = read();
         // cin >> op[i];
         if(op[i] == 1) {
            int k;
            k = read();
            // cin >> k;
            for(int j = 1 ; j <= k ; j++) {
               int x;
               x = read();
               // cin >> x;
               F[i].push_back(x);
            }
         }else if(op[i] == 2) {
            int x,y;
            // cin >> x >> y;
            x = read();
            y = read();
            G[i].push_back(x);
            G[i].push_back(y);
            din[x]++;
            din[y]++;
         }
     }
     queue<int>q;
     for(int i = 1 ; i <= n ; i++) {
         if(din[i] == 0) {
            q.push(i);
            if(i == n) cnt[n] = 1;
         }
     }
     while(q.size()) {
         int u = q.front();
         q.pop();
         for(auto v : G[u]) {
            din[v]--;
            cnt[v] += cnt[u];
            if(din[v] == 0) {
               q.push(v);
            }
         }
     }
     map<int,int>mp;
     int sum = 0;
     int maxx = 0;
     for(int i = 1 ; i <= n ; i++) {
         if(op[i] == 2) continue;
         for(auto x : F[i]) {
            mp[x] += cnt[i];
            sum += cnt[i];
            maxx = max(maxx,mp[x]);
         }
     }
     int ans = 0; 
     int res = sum - maxx;
     if(maxx * 2 <= sum) {
         ans = sum;
     }else {
         ans = res * 2;
     }
     cout << ans << endl;
}
signed main()
{     
   // cin.tie(nullptr); 
   // ios::sync_with_stdio(false); 
   int kk = 1;
   cin >> kk;
   //cin.get(); 
   while(kk--) solve();
   return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 9716kb

input:

2
1
1 5 3 3 2 1 3
3
1 3 3 3 2
1 4 2 2 3 3
2 1 2

output:

4
6

result:

ok 2 lines

Test #2:

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

input:

10000
100
1 30 371028678 371028678 371028678 716418076 398221499 591504380 398221499 398221499 591504380 777141390 398221499 591504380 591504380 777141390 287847807 716418076 777141390 716418076 777141390 287847807 287847807 287847807 371028678 371028678 398221499 777141390 371028678 6827702 6827702...

output:

700
68
332
284
131
1048
194
667
704
0
484
252
35
351
1228
238
1025
354
383
571
4272
340
1044
199
448
190
0
69
841
546
247
883
138
1633
91
3308
2556
1280
488
618
407
381
383
2865
0
496
1202
53
0
415
662
380
41
18
91
505
818
603
241
764
1227
1802
176
187
817
1489
460
296
238
236
1028
0
606
1696
746
10...

result:

ok 10000 lines

Test #3:

score: 0
Accepted
time: 119ms
memory: 9916kb

input:

1000
1000
1 95 626416845 75969860 75969860 75969860 75969860 75969860 626416845 75969860 626416845 626416845 626416845 626416845 75969860 75969860 75969860 626416845 75969860 626416845 626416845 75969860 626416845 75969860 75969860 626416845 75969860 626416845 626416845 75969860 75969860 75969860 62...

output:

7496
113951
17628
151136
92998
49984
39422
57746
0
28271
27458
0
127054
13854
68249
32166
280419
70120
0
0
47941
71104
93032
21042
30012
0
0
14482
20938
66600
94605
129973
145603
16366
43924
0
9923
18731
0
249292
8847
30154
288759
0
86256
30372
156418
247862
91672
38330
89806
27911
137951
166924
189...

result:

ok 1000 lines

Test #4:

score: 0
Accepted
time: 144ms
memory: 11040kb

input:

100
10000
1 1354 265069553 265069553 729542591 729542591 729542591 729542591 729542591 729542591 729542591 265069553 265069553 265069553 729542591 729542591 265069553 729542591 265069553 729542591 265069553 729542591 265069553 265069553 265069553 265069553 265069553 265069553 729542591 265069553 265...

output:

2156412
5940042
1932718
2497609
3287092
0
5176818
7057040
26127674
6268925
0
3298524
6134142
0
0
0
2293094
0
67966
0
708927
0
3540522
205067
0
791702
3283922
0
5278171
8734406
3719656
0
5635776
3559716
0
5795392
4238756
1752825
0
17244508
398074
0
12989840
0
0
849320
211188
545453
4409794
0
4164304
...

result:

ok 100 lines

Test #5:

score: -100
Wrong Answer
time: 221ms
memory: 21876kb

input:

10
100000
1 11020 495408904 495408904 377631092 377631092 377631092 377631092 495408904 377631092 377631092 377631092 495408904 377631092 495408904 495408904 377631092 495408904 495408904 495408904 377631092 495408904 377631092 495408904 377631092 495408904 495408904 495408904 495408904 377631092 49...

output:

306812544
192374690
1183915769
0
19322750
795133717
1281613237
77446187
657488136
227127642

result:

wrong answer 3rd lines differ - expected: '0', found: '1183915769'