提出 #36027453
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(NULL)->ios_base::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
vector<array<int, 4>> bus(m);
vector<vector<pair<int, int>>> state(n + 1);
for (int i = 0; i < m; ++i) {
int u, v, s, t;
cin >> u >> v >> s >> t;
bus[i] = {u, v, s, t};
state[u].push_back({s, i});
}
for (int i = 1; i <= n; ++i) {
sort(state[i].begin(), state[i].end());
}
int mm = log2(m) + 1;
auto f = vector(m, vector(mm, -1));
auto get = [&](int p, int t) {
auto it = lower_bound(state[p].begin(), state[p].end(), make_pair(t, 0));
if (it == state[p].end())
return -p;
return it->second;
};
for (int i = 0; i < m; ++i) {
f[i][0] = get(bus[i][1], bus[i][3]);
}
for (int i = 1; i < mm; ++i) {
for (int j = 0; j < m; ++j) {
if (f[j][i - 1] >= 0)
f[j][i] = f[f[j][i - 1]][i - 1];
else
f[j][i] = f[j][i - 1];
}
}
for (int i = 1; i <= k; ++i) {
int t1, u, t2;
cin >> t1 >> u >> t2;
int a = get(u, t1);
//cout << "a = " << a << endl;
if (a < 0 || bus[a][2] >= t2) {
cout << u << "\n";
continue;
}
for (int i = mm - 1; i >= 0; --i) {
auto b = f[a][i];
if (b >= 0 && bus[b][2] < t2)
a = b;
}
if (bus[a][3] >= t2) {
cout << bus[a][0] << " " << bus[a][1] << "\n";
} else {
cout << bus[a][1] << "\n";
}
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Greedy Takahashi |
| ユーザ | SkqLiiiao |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 500 |
| コード長 | 1676 Byte |
| 結果 | AC |
| 実行時間 | 186 ms |
| メモリ | 20520 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, example0.txt, example1.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 40 ms | 3492 KiB |
| 001.txt | AC | 112 ms | 19388 KiB |
| 002.txt | AC | 104 ms | 17580 KiB |
| 003.txt | AC | 116 ms | 19060 KiB |
| 004.txt | AC | 44 ms | 5504 KiB |
| 005.txt | AC | 49 ms | 13236 KiB |
| 006.txt | AC | 26 ms | 8780 KiB |
| 007.txt | AC | 125 ms | 15772 KiB |
| 008.txt | AC | 125 ms | 15904 KiB |
| 009.txt | AC | 126 ms | 20424 KiB |
| 010.txt | AC | 107 ms | 20392 KiB |
| 011.txt | AC | 126 ms | 20488 KiB |
| 012.txt | AC | 126 ms | 20480 KiB |
| 013.txt | AC | 125 ms | 20440 KiB |
| 014.txt | AC | 107 ms | 20388 KiB |
| 015.txt | AC | 99 ms | 20488 KiB |
| 016.txt | AC | 116 ms | 20520 KiB |
| 017.txt | AC | 125 ms | 15776 KiB |
| 018.txt | AC | 109 ms | 19280 KiB |
| 019.txt | AC | 109 ms | 19432 KiB |
| 020.txt | AC | 83 ms | 15984 KiB |
| 021.txt | AC | 50 ms | 3832 KiB |
| 022.txt | AC | 49 ms | 3872 KiB |
| 023.txt | AC | 43 ms | 3724 KiB |
| 024.txt | AC | 186 ms | 19756 KiB |
| 025.txt | AC | 177 ms | 19316 KiB |
| 026.txt | AC | 170 ms | 15692 KiB |
| 027.txt | AC | 177 ms | 19376 KiB |
| 028.txt | AC | 173 ms | 19280 KiB |
| 029.txt | AC | 177 ms | 19432 KiB |
| example0.txt | AC | 5 ms | 3612 KiB |
| example1.txt | AC | 2 ms | 3688 KiB |