Code Submission Evaluation System Login

HIIT Open 2017

Start:2017-05-27 11:00:00
End:2017-05-27 16:00:00
 

Tasks | Messages | Scoreboard | Statistics


CSES - HIIT Open 2017 - Results
History
2017-05-27 15:57:37
2017-05-27 15:56:25
2017-05-27 15:52:57
2017-05-27 15:45:07
Task:Factory
Sender:Kanadan virallinen maajoukkue
Submission time:2017-05-27 15:57:37
Language:C++
Status:READY
Result:WRONG ANSWER

Test results

testverdicttime (s)
#1ACCEPTED0.06 / 1.00details
#2ACCEPTED0.04 / 1.00details
#3ACCEPTED0.04 / 1.00details
#4ACCEPTED0.05 / 1.00details
#5ACCEPTED0.11 / 1.00details
#6ACCEPTED0.10 / 1.00details
#7ACCEPTED0.10 / 1.00details
#8WRONG ANSWER0.09 / 1.00details
#9ACCEPTED0.09 / 1.00details
#10WRONG ANSWER0.08 / 1.00details
#11ACCEPTED0.09 / 1.00details
#12ACCEPTED0.12 / 1.00details
#13ACCEPTED0.10 / 1.00details
#14ACCEPTED0.12 / 1.00details
#15ACCEPTED0.10 / 1.00details
#16ACCEPTED0.05 / 1.00details
#17ACCEPTED0.05 / 1.00details

Code

#include<iostream>
#include<queue>
#include<stack>
#include<vector>

using namespace std;

// JUST
// DO
// IT

vector<int> vl[501];
int in[501];
stack<int> alut;

void poista(int pois){
    in[pois]=-1;
    for(int seur:vl[pois]){
        in[seur]--;
        if(in[seur]==0)
            alut.push(seur);
    }
}


int main(){
    int n, m;
    cin>>n>>m;
    
    for(int i=0; i<m; i++){
        int a,b;
        cin>>a>>b;
        vl[a].push_back(b);
        in[b]++;
    }
    
    for(int i=1; i<=n; i++)
        if(in[i]==0)
            alut.push(i);
            
            
    int days=0;
    while(alut.size()){
        if(alut.size()==1){
            int pois=alut.top();
            alut.pop();
            poista(pois);
            days++;
        }else{
            if(alut.size() == 2 || alut.size() >= 4){
                int p1=alut.top();
                alut.pop();
                int p2=alut.top();
                alut.pop();
                
                poista(p1);
                poista(p2);
                days++;              
            }else{
                vector<int> kaikk;
                days++;
                while(alut.size()){
                    kaikk.push_back(alut.top());
                    alut.pop();
                } 
           
                for(int i:kaikk)
                    poista(i);
                
                int paras=0;
                int lisaa=10000000;
                for(int i:kaikk){
                    int pt=0;
                    for(int seur : vl[i])
                        if(in[seur] == 0)
                            pt++;
                    if(pt<lisaa){
                        paras=i;
                        lisaa=pt;
                    }
                }
                
                in[paras]=0;
                for(int seur:vl[paras])
                    in[seur]++;
                alut = stack<int>();
                
                for(int i=1; i<=n; i++)
                    if(in[i]==0)
                        alut.push(i);
                        
                        
                   
            }
        }
    }
    
    cout<<days<<endl;
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
1 0
view   save

correct output
1
view   save

user output
1
view   save

Test 2

Verdict: ACCEPTED

input
2 0
view   save

correct output
1
view   save

user output
1
view   save

Test 3

Verdict: ACCEPTED

input
2 1
2 1
view   save

correct output
2
view   save

user output
2
view   save

Test 4

Verdict: ACCEPTED

input
500 0
view   save

correct output
250
view   save

user output
250
view   save

Test 5

Verdict: ACCEPTED

input
500 124750
66 104
50 159
173 457
200 154
416 492
232 191
205 323
201 403
476 348
191 266
239 422
103 442
295 79
191 352
124 451
97 463
353 194
153 82
166 386
...
view   save

correct output
500
view   save

user output
500
view   save

Test 6

Verdict: ACCEPTED

input
500 96771
376 390
243 497
417 360
107 80
200 177
107 17
117 486
348 434
262 43
155 79
160 178
247 365
354 101
232 352
414 16
438 80
482 118
484 76
250 183
...
view   save

correct output
413
view   save

user output
413
view   save

Test 7

Verdict: ACCEPTED

input
500 106799
96 245
68 62
122 119
460 454
378 409
238 455
262 455
217 35
368 195
318 374
215 496
301 311
255 296
171 95
9 431
284 272
261 258
28 316
489 178
...
view   save

correct output
433
view   save

user output
433
view   save

Test 8

Verdict: WRONG ANSWER

input
500 83550
76 338
111 174
88 142
114 463
416 168
299 273
373 231
495 345
104 414
416 161
141 21
139 348
381 300
290 414
477 487
173 155
161 260
245 300
465 453
...
view   save

correct output
365
view   save

user output
366
view   save

Test 9

Verdict: ACCEPTED

input
500 98051
281 60
312 284
270 474
385 224
218 419
201 242
189 271
493 132
344 102
314 408
52 61
21 192
493 486
26 352
227 114
80 296
121 141
457 288
339 410
...
view   save

correct output
410
view   save

user output
410
view   save

Test 10

Verdict: WRONG ANSWER

input
500 86622
5 320
50 107
182 483
385 500
280 389
211 467
423 385
88 310
336 130
44 216
320 489
202 105
217 343
42 398
153 200
351 8
318 61
342 322
113 423
...
view   save

correct output
372
view   save

user output
373
view   save

Test 11

Verdict: ACCEPTED

input
500 99445
421 286
392 406
155 290
475 453
316 105
276 310
325 275
428 21
40 137
211 236
194 89
85 259
87 481
342 299
458 132
382 207
447 49
496 242
308 204
...
view   save

correct output
396
view   save

user output
396
view   save

Test 12

Verdict: ACCEPTED

input
500 99832
283 149
315 396
264 422
224 388
372 391
333 58
441 470
203 48
323 385
218 366
17 333
176 115
341 107
73 448
380 340
249 165
274 99
345 446
199 399
...
view   save

correct output
410
view   save

user output
410
view   save

Test 13

Verdict: ACCEPTED

input
500 116149
446 185
232 35
498 391
189 63
252 474
410 472
132 35
41 475
418 173
343 489
131 39
220 241
333 348
17 333
399 257
70 23
89 488
141 122
171 478
...
view   save

correct output
457
view   save

user output
457
view   save

Test 14

Verdict: ACCEPTED

input
500 84757
71 205
286 360
184 486
30 228
230 365
334 386
20 65
131 2
144 189
276 109
225 311
23 242
453 458
414 149
75 70
10 445
66 236
41 356
124 27
...
view   save

correct output
364
view   save

user output
364
view   save

Test 15

Verdict: ACCEPTED

input
500 108617
126 250
76 224
449 69
200 63
405 344
143 474
80 131
480 165
135 266
113 369
13 271
287 100
208 167
113 90
145 440
158 427
341 460
404 101
118 373
...
view   save

correct output
439
view   save

user output
439
view   save

Test 16

Verdict: ACCEPTED

input
10 20
7 8
1 3
4 8
5 9
2 8
1 7
4 3
10 5
6 5
9 3
10 3
2 4
6 9
1 5
2 3
7 3
5 4
10 7
1 2
...
view   save

correct output
5
view   save

user output
5
view   save

Test 17

Verdict: ACCEPTED

input
10 20
2 9
9 8
4 3
7 3
5 1
5 10
2 1
4 10
2 8
4 7
5 8
4 6
5 9
10 6
5 7
4 9
9 10
5 6
7 10
...
view   save

correct output
5
view   save

user output
5
view   save