답안 #471969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471969 2021-09-12T02:53:14 Z SHZhang 장난감 기차 (IOI17_train) C++14
26 / 100
2000 ms 89324 KB
#include <vector>
#include <queue>
#include "train.h"

using namespace std;

int n, m;
vector<int> rgraph[5005];
int f[5005];
int freq[5005][5005];

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	n = (int)a.size();
    m = (int)u.size();
    for (int i = 0; i < m; i++) {
        rgraph[v[i]].push_back(u[i]);
        freq[u[i]][0]++;
    }
    queue<pair<int, pair<int, int> > > que;
    for (int i = 0; i < n; i++) {
        if (r[i]) {
            f[i] = 1;
            que.push(make_pair(i, make_pair(0, 1)));
        }
    }
    while (!que.empty()) {
        pair<int, pair<int, int> > pr = que.front();
        //fprintf(stderr, "! %d %d\n", pr.first, pr.second);
        int cur = pr.first; que.pop();
        for (int idx = 0; idx < rgraph[cur].size(); idx++) {
            int pre = rgraph[cur][idx];
            if (f[pre] > n) continue;
            if (a[pre]) {
                int newf = min(f[cur] + r[pre], n + 1);
                if (newf > f[pre]) {
                    que.push(make_pair(pre, make_pair(f[pre], newf)));
                    f[pre] = newf;
                }
            } else {
                freq[pre][pr.second.first]--;
                freq[pre][pr.second.second]++;
                //fprintf(stderr, "freq %d -%d +%d => %d %d\n", pre, pr.second, f[cur], freq[pre][pr.second], freq[pre][f[cur]]);
                int old_f = f[pre];
                while (freq[pre][f[pre] - r[pre]] == 0 && f[pre] < n + 1) f[pre]++;
                if (f[pre] > old_f) {
                    que.push(make_pair(pre, make_pair(old_f, f[pre])));
                }
            }
        }
    }
    vector<int> ans;
    for (int i = 0; i < n; i++) {
        //fprintf(stderr, "%d ", f[i]);
        ans.push_back(f[i] > n ? 1 : 0);
    }
    return ans;
}

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:30:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (int idx = 0; idx < rgraph[cur].size(); idx++) {
      |                           ~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 606 ms 40640 KB Output is correct
2 Correct 581 ms 39956 KB Output is correct
3 Correct 577 ms 40260 KB Output is correct
4 Correct 530 ms 38724 KB Output is correct
5 Correct 571 ms 39244 KB Output is correct
6 Correct 594 ms 40512 KB Output is correct
7 Correct 172 ms 33640 KB Output is correct
8 Correct 626 ms 21160 KB Output is correct
9 Correct 595 ms 40920 KB Output is correct
10 Correct 574 ms 40568 KB Output is correct
11 Correct 555 ms 40900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 404 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 21276 KB Output is correct
2 Correct 170 ms 21196 KB Output is correct
3 Correct 220 ms 21244 KB Output is correct
4 Correct 558 ms 62568 KB Output is correct
5 Correct 720 ms 57192 KB Output is correct
6 Correct 43 ms 21196 KB Output is correct
7 Correct 64 ms 26276 KB Output is correct
8 Correct 543 ms 21152 KB Output is correct
9 Correct 17 ms 21220 KB Output is correct
10 Correct 754 ms 21304 KB Output is correct
11 Correct 684 ms 21232 KB Output is correct
12 Correct 19 ms 21196 KB Output is correct
13 Correct 1503 ms 21220 KB Output is correct
14 Correct 1533 ms 21272 KB Output is correct
15 Correct 1516 ms 21224 KB Output is correct
16 Correct 1476 ms 21316 KB Output is correct
17 Correct 1511 ms 21196 KB Output is correct
18 Correct 131 ms 21048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2090 ms 89324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1888 ms 79504 KB Output is correct
2 Execution timed out 2024 ms 37700 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 606 ms 40640 KB Output is correct
2 Correct 581 ms 39956 KB Output is correct
3 Correct 577 ms 40260 KB Output is correct
4 Correct 530 ms 38724 KB Output is correct
5 Correct 571 ms 39244 KB Output is correct
6 Correct 594 ms 40512 KB Output is correct
7 Correct 172 ms 33640 KB Output is correct
8 Correct 626 ms 21160 KB Output is correct
9 Correct 595 ms 40920 KB Output is correct
10 Correct 574 ms 40568 KB Output is correct
11 Correct 555 ms 40900 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 404 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 97 ms 21276 KB Output is correct
33 Correct 170 ms 21196 KB Output is correct
34 Correct 220 ms 21244 KB Output is correct
35 Correct 558 ms 62568 KB Output is correct
36 Correct 720 ms 57192 KB Output is correct
37 Correct 43 ms 21196 KB Output is correct
38 Correct 64 ms 26276 KB Output is correct
39 Correct 543 ms 21152 KB Output is correct
40 Correct 17 ms 21220 KB Output is correct
41 Correct 754 ms 21304 KB Output is correct
42 Correct 684 ms 21232 KB Output is correct
43 Correct 19 ms 21196 KB Output is correct
44 Correct 1503 ms 21220 KB Output is correct
45 Correct 1533 ms 21272 KB Output is correct
46 Correct 1516 ms 21224 KB Output is correct
47 Correct 1476 ms 21316 KB Output is correct
48 Correct 1511 ms 21196 KB Output is correct
49 Correct 131 ms 21048 KB Output is correct
50 Execution timed out 2090 ms 89324 KB Time limit exceeded
51 Halted 0 ms 0 KB -