Submission #00170
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #include <bits/stdc++.h> using namespace std; #define int long long vector< int > dag[1010]; vector<pair< int , pair< int , int > > > graph[1010]; list< int > out; int toyama[1010]; int memo[1010][1010]; int n, p; int dp( const int yta, const int ydk){ if (memo[yta][ydk] != -1){ return memo[yta][ydk]; } int ans = LLONG_MAX; if (yta == ydk){ if (yta == n-1){ return 0; } for ( int i = 0;i < graph[yta].size();i++){ for ( int j = 0;j < graph[ydk].size();j++){ if (i == j){ ans = min(ans, dp(graph[yta][i].first, graph[ydk][j].first) + graph[yta][i].second.first + graph[yta][i].second.second); } else { ans = min(ans, dp(graph[yta][i].first, graph[ydk][j].first) + graph[yta][i].second.first + graph[ydk][j].second.first); } } } } else { if (toyama[yta] < toyama[ydk]){ for ( int i = 0;i < graph[yta].size();i++){ ans = min(ans, dp(graph[yta][i].first, ydk) + graph[yta][i].second.first); } } else { for ( int i = 0;i < graph[ydk].size();i++){ ans = min(ans, dp(yta, graph[ydk][i].first) + graph[ydk][i].second.first); } } } return memo[yta][ydk] = ans; } int visited[1010] = {}; void dfs( int idx){ visited[idx] = 1; for ( int i = 0;i < dag[idx].size();i++){ int v = dag[idx][i]; if (!visited[v]) dfs(v); } out.push_front(idx); } signed main(){ cin >> n >> p; for ( int i = 0;i < p;i++){ int s, e, t1, t2; cin >> s >> e >> t1 >> t2; s--; e--; graph[s].push_back({e, {t1, t2}}); dag[s].push_back(e); } for ( int i = 0;i < n;i++){ if (!visited[i]){ dfs(i); } } int cnt = 0; for (auto itr = out.begin(); itr != out.end();itr++){ toyama[*itr] = cnt; cnt++; } memset (memo, -1, sizeof (memo)); cout << dp(0, 0) << endl; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0010 - 滑降競技 |
ユーザー名 | ARUMAKAN |
投稿日時 | 2019-09-10 17:59:22 |
言語 | C++14 |
状態 | Accepted |
得点 | 15 |
ソースコード長 | 2162 Byte |
最大実行時間 | 43 ms |
最大メモリ使用量 | 9068 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 15 / 15 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
02_rand_00.in | AC | 30 ms | 8668 KB |
1
|
02_rand_01.in | AC | 18 ms | 8544 KB |
1
|
02_rand_02.in | AC | 23 ms | 8556 KB |
1
|
02_rand_03.in | AC | 18 ms | 8568 KB |
1
|
02_rand_04.in | AC | 25 ms | 8580 KB |
1
|
02_rand_05.in | AC | 39 ms | 8592 KB |
1
|
02_rand_06.in | AC | 27 ms | 8604 KB |
1
|
02_rand_07.in | AC | 24 ms | 8612 KB |
1
|
02_rand_08.in | AC | 26 ms | 8624 KB |
1
|
02_rand_09.in | AC | 31 ms | 8632 KB |
1
|
02_rand_10.in | AC | 30 ms | 8640 KB |
1
|
02_rand_11.in | AC | 27 ms | 8644 KB |
1
|
02_rand_12.in | AC | 27 ms | 8652 KB |
1
|
02_rand_13.in | AC | 26 ms | 8664 KB |
1
|
02_rand_14.in | AC | 22 ms | 8540 KB |
1
|
03_corner_00.in | AC | 34 ms | 8804 KB |
1
|
100_test_00.in | AC | 25 ms | 8676 KB |
1
|
100_test_01.in | AC | 22 ms | 8688 KB |
1
|
100_test_02.in | AC | 28 ms | 8696 KB |
1
|
100_test_03.in | AC | 22 ms | 8700 KB |
1
|
100_test_04.in | AC | 20 ms | 8580 KB |
1
|
100_test_05.in | AC | 27 ms | 8584 KB |
1
|
100_test_06.in | AC | 27 ms | 8588 KB |
1
|
100_test_07.in | AC | 26 ms | 8596 KB |
1
|
100_test_08.in | AC | 24 ms | 8604 KB |
1
|
100_test_09.in | AC | 29 ms | 8608 KB |
1
|
100_test_10.in | AC | 23 ms | 8608 KB |
1
|
100_test_11.in | AC | 20 ms | 8608 KB |
1
|
100_test_12.in | AC | 23 ms | 8616 KB |
1
|
100_test_13.in | AC | 31 ms | 8620 KB |
1
|
100_test_14.in | AC | 25 ms | 8628 KB |
1
|
100_test_15.in | AC | 23 ms | 8628 KB |
1
|
100_test_16.in | AC | 26 ms | 8632 KB |
1
|
100_test_17.in | AC | 24 ms | 8632 KB |
1
|
100_test_18.in | AC | 25 ms | 8632 KB |
1
|
100_test_19.in | AC | 27 ms | 8632 KB |
1
|
101_test_00.in | AC | 25 ms | 8628 KB |
1
|
101_test_01.in | AC | 30 ms | 8632 KB |
1
|
101_test_02.in | AC | 23 ms | 8640 KB |
1
|
101_test_03.in | AC | 19 ms | 8644 KB |
1
|
101_test_04.in | AC | 23 ms | 8652 KB |
1
|
101_test_05.in | AC | 21 ms | 8660 KB |
1
|
101_test_06.in | AC | 22 ms | 8664 KB |
1
|
101_test_07.in | AC | 23 ms | 8664 KB |
1
|
101_test_08.in | AC | 25 ms | 8796 KB |
1
|
101_test_09.in | AC | 21 ms | 8796 KB |
1
|
101_test_10.in | AC | 23 ms | 8796 KB |
1
|
101_test_11.in | AC | 20 ms | 8804 KB |
1
|
102_test_00.in | AC | 27 ms | 8936 KB |
1
|
102_test_01.in | AC | 22 ms | 8904 KB |
1
|
102_test_02.in | AC | 24 ms | 8868 KB |
1
|
102_test_03.in | AC | 24 ms | 8836 KB |
1
|
102_test_04.in | AC | 28 ms | 8892 KB |
1
|
102_test_05.in | AC | 24 ms | 8924 KB |
1
|
103_test_00.in | AC | 27 ms | 8920 KB |
1
|
103_test_01.in | AC | 25 ms | 8848 KB |
1
|
103_test_02.in | AC | 27 ms | 8804 KB |
1
|
103_test_03.in | AC | 34 ms | 8804 KB |
1
|
103_test_04.in | AC | 38 ms | 8804 KB |
1
|
103_test_05.in | AC | 27 ms | 8936 KB |
1
|
103_test_06.in | AC | 23 ms | 9068 KB |
1
|
103_test_07.in | AC | 43 ms | 8940 KB |
1
|
104_test_00.in | AC | 22 ms | 8684 KB |
1
|