# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
120052 |
2019-06-23T06:25:01 Z |
E869120 |
File Paths (BOI15_fil) |
C++14 |
|
1000 ms |
84988 KB |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)
int N, M, K, S, dist[6009], dp[6009][6009], num1[1000009], num2[1000009]; bool used[6009], flag[6009];
vector<pair<int, int>>G[6009], I[6009];
vector<int>E1, E2, F1[100009], F2[100009];
void dfs1(int pos, int dep) {
dist[pos] = dep;
for (int i = 0; i < G[pos].size(); i++) dfs1(G[pos][i].first, dep + G[pos][i].second);
}
void dfs2(int root, int pos, int dep) {
if (dp[root][pos] != (1 << 30)) return;
dp[root][pos] = dep;
for (int i = 0; i < I[pos].size(); i++) dfs2(root, I[pos][i].first, dep + I[pos][i].second);
}
int main() {
scanf("%d%d%d%d", &N, &M, &K, &S); S++;
for (int i = 1; i <= N + M; i++) {
int p, l; scanf("%d%d", &p, &l); l++;
G[p].push_back(make_pair(i, l));
I[p].push_back(make_pair(i, l));
I[i].push_back(make_pair(p, l));
}
// 前準備
dfs1(0, 0);
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N + M; j++) dp[i][j] = (1 << 30);
dfs2(i, i, 0);
}
for (int i = N + 1; i <= N + M; i++) {
E1.push_back(dist[i]);
for (int j = 1; j * j <= (K - dist[i]); j++) {
if ((K - dist[i]) % j != 0) continue;
E2.push_back(j);
E2.push_back((K - dist[i]) / j);
}
}
sort(E1.begin(), E1.end()); E1.erase(unique(E1.begin(), E1.end()), E1.end());
sort(E2.begin(), E2.end()); E2.erase(unique(E2.begin(), E2.end()), E2.end());
for (int i = 0; i <= 1000000; i++) num1[i] = lower_bound(E1.begin(), E1.end(), i) - E1.begin();
for (int i = 0; i <= 1000000; i++) num2[i] = lower_bound(E2.begin(), E2.end(), i) - E2.begin();
// 全探索
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N; j++) {
if (dist[i] >= dist[j] && dist[j] + dp[j][i] == dist[i]) {
int cl = dp[j][i] + S; if (cl < 0 || cl > K) continue;
int pos1 = num2[cl];
if (pos1 < E2.size() && E2[pos1] == cl) F2[pos1].push_back(j);
}
else {
int cl = dist[i] + S - dist[j]; cl = K - cl;
int pos1 = num1[cl]; if (cl < 0 || cl > K) continue;
if (pos1 < E1.size() && E1[pos1] == cl) F1[pos1].push_back(j);
}
}
}
for (int i = 0; i < E1.size(); i++) {
for (int j = 0; j <= N + M; j++) used[j] = false;
for (int j = 0; j < F1[i].size(); j++) used[F1[i][j]] = true;
for (int j = 0; j <= N; j++) {
if (used[j] == false) continue;
for (int k = 0; k < G[j].size(); k++) used[G[j][k].first] = true;
}
for (int j = N + 1; j <= N + M; j++) { if (used[j] == true && dist[j] == E1[i]) flag[j] = true; }
}
for (int i = 0; i < E2.size(); i++) {
for (int j = 0; j <= N + M; j++) used[j] = false;
for (int j = 0; j < F2[i].size(); j++) used[F2[i][j]] = true;
for (int j = 0; j <= N; j++) {
if (used[j] == false) continue;
for (int k = 0; k < G[j].size(); k++) used[G[j][k].first] = true;
}
for (int j = N + 1; j <= N + M; j++) { if (used[j] == true && (K - dist[j]) % E2[i] == 0) flag[j] = true; }
}
for (int i = N + 1; i <= N + M; i++) {
if (flag[i] == true) printf("YES\n");
else printf("NO\n");
}
return 0;
}
Compilation message
fil.cpp:5:0: warning: ignoring #pragma warning [-Wunknown-pragmas]
#pragma warning (disable: 4996)
fil.cpp: In function 'void dfs1(int, int)':
fil.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < G[pos].size(); i++) dfs1(G[pos][i].first, dep + G[pos][i].second);
~~^~~~~~~~~~~~~~~
fil.cpp: In function 'void dfs2(int, int, int)':
fil.cpp:19:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < I[pos].size(); i++) dfs2(root, I[pos][i].first, dep + I[pos][i].second);
~~^~~~~~~~~~~~~~~
fil.cpp: In function 'int main()':
fil.cpp:57:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (pos1 < E2.size() && E2[pos1] == cl) F2[pos1].push_back(j);
~~~~~^~~~~~~~~~~
fil.cpp:62:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (pos1 < E1.size() && E1[pos1] == cl) F1[pos1].push_back(j);
~~~~~^~~~~~~~~~~
fil.cpp:67:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < E1.size(); i++) {
~~^~~~~~~~~~~
fil.cpp:69:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < F1[i].size(); j++) used[F1[i][j]] = true;
~~^~~~~~~~~~~~~~
fil.cpp:72:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < G[j].size(); k++) used[G[j][k].first] = true;
~~^~~~~~~~~~~~~
fil.cpp:77:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < E2.size(); i++) {
~~^~~~~~~~~~~
fil.cpp:79:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < F2[i].size(); j++) used[F2[i][j]] = true;
~~^~~~~~~~~~~~~~
fil.cpp:82:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int k = 0; k < G[j].size(); k++) used[G[j][k].first] = true;
~~^~~~~~~~~~~~~
fil.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d", &N, &M, &K, &S); S++;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
fil.cpp:25:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int p, l; scanf("%d%d", &p, &l); l++;
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
13816 KB |
Output is correct |
2 |
Correct |
46 ms |
15992 KB |
Output is correct |
3 |
Correct |
59 ms |
17232 KB |
Output is correct |
4 |
Correct |
59 ms |
16220 KB |
Output is correct |
5 |
Correct |
60 ms |
17272 KB |
Output is correct |
6 |
Correct |
62 ms |
17272 KB |
Output is correct |
7 |
Correct |
94 ms |
17272 KB |
Output is correct |
8 |
Correct |
56 ms |
17276 KB |
Output is correct |
9 |
Correct |
56 ms |
17272 KB |
Output is correct |
10 |
Correct |
24 ms |
13176 KB |
Output is correct |
11 |
Correct |
44 ms |
17016 KB |
Output is correct |
12 |
Correct |
38 ms |
15984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
729 ms |
84572 KB |
Output is correct |
2 |
Correct |
783 ms |
84744 KB |
Output is correct |
3 |
Correct |
730 ms |
84728 KB |
Output is correct |
4 |
Correct |
915 ms |
84600 KB |
Output is correct |
5 |
Correct |
842 ms |
84880 KB |
Output is correct |
6 |
Correct |
962 ms |
84956 KB |
Output is correct |
7 |
Correct |
876 ms |
84728 KB |
Output is correct |
8 |
Correct |
951 ms |
84728 KB |
Output is correct |
9 |
Correct |
718 ms |
84760 KB |
Output is correct |
10 |
Correct |
733 ms |
84600 KB |
Output is correct |
11 |
Correct |
548 ms |
79336 KB |
Output is correct |
12 |
Correct |
467 ms |
76572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
13816 KB |
Output is correct |
2 |
Correct |
46 ms |
15992 KB |
Output is correct |
3 |
Correct |
59 ms |
17232 KB |
Output is correct |
4 |
Correct |
59 ms |
16220 KB |
Output is correct |
5 |
Correct |
60 ms |
17272 KB |
Output is correct |
6 |
Correct |
62 ms |
17272 KB |
Output is correct |
7 |
Correct |
94 ms |
17272 KB |
Output is correct |
8 |
Correct |
56 ms |
17276 KB |
Output is correct |
9 |
Correct |
56 ms |
17272 KB |
Output is correct |
10 |
Correct |
24 ms |
13176 KB |
Output is correct |
11 |
Correct |
44 ms |
17016 KB |
Output is correct |
12 |
Correct |
38 ms |
15984 KB |
Output is correct |
13 |
Correct |
729 ms |
84572 KB |
Output is correct |
14 |
Correct |
783 ms |
84744 KB |
Output is correct |
15 |
Correct |
730 ms |
84728 KB |
Output is correct |
16 |
Correct |
915 ms |
84600 KB |
Output is correct |
17 |
Correct |
842 ms |
84880 KB |
Output is correct |
18 |
Correct |
962 ms |
84956 KB |
Output is correct |
19 |
Correct |
876 ms |
84728 KB |
Output is correct |
20 |
Correct |
951 ms |
84728 KB |
Output is correct |
21 |
Correct |
718 ms |
84760 KB |
Output is correct |
22 |
Correct |
733 ms |
84600 KB |
Output is correct |
23 |
Correct |
548 ms |
79336 KB |
Output is correct |
24 |
Correct |
467 ms |
76572 KB |
Output is correct |
25 |
Correct |
724 ms |
84656 KB |
Output is correct |
26 |
Correct |
705 ms |
84516 KB |
Output is correct |
27 |
Correct |
712 ms |
84600 KB |
Output is correct |
28 |
Correct |
712 ms |
84572 KB |
Output is correct |
29 |
Correct |
937 ms |
84728 KB |
Output is correct |
30 |
Correct |
906 ms |
84740 KB |
Output is correct |
31 |
Execution timed out |
1012 ms |
84988 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |