#include "Aoi.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
namespace {
typedef long long ll;
struct pii{int a, b;};
bool operator <(pii a, pii b) {return a.a < b.a || a.a == b.a && a.b < b.b;}
struct edge{int t; ll len;};
struct node{int i; ll to;};
bool operator <(node a, node b){
return a.to > b.to;
}
const ll INF = 1e17;
}
std::string aoi(int N, int M, int Q, int K, std::vector<int> A,
std::vector<int> B, std::vector<long long> C,
std::vector<int> T, std::vector<int> X) {
string ret;
vector<vector<edge>> adj(N);
map<pii, int> xi;
forR(i, M){
adj[A[i]].push_back({B[i], C[i]});
adj[B[i]].push_back({A[i], C[i]});
}
forR(i, K){
xi.insert({{A[X[i]], B[X[i]]}, i});
xi.insert({{B[X[i]], A[X[i]]}, i});
}
// dijkstra
vector<ll> dis(N, INF);
vector<bool> vis(N);
vector<int> pre(N);
priority_queue<node> dij;
dij.push({0, 0});
dis[0] = 0;
while(!dij.empty()){
auto [cur, len] = dij.top();
dij.pop();
if(!vis[cur]){
vis[cur] = true;
for(auto [to, el] : adj[cur]){
if(len + el < dis[to]){
dis[to] = len + el;
pre[to] = cur;
dij.push({to, dis[to]});
}
}
}
}
forR(i, Q){
vector<int> pth;
for(int j = T[i]; j != 0; j = pre[j]) pth.push_back(j);
pth.push_back(0);
reverse(all(pth));
string app = "";
forR(j, K) app.push_back('0');
forR(j, (int) pth.size() - 1){
if(xi.count({pth[j], pth[j+1]})) {
app[xi[{pth[j],pth[j+1]}]] = '1';
}
}
ret += app;
}
cerr << ret << '\n';
return ret;
}
#include "Bitaro.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
namespace {
typedef long long ll;
struct pii{int a, b;};
bool operator <(pii a, pii b) {return a.a < b.a || a.a == b.a && a.b < b.b;}
struct edge{int t, ind; ll len;};
struct node{int i; ll to;};
bool operator <(node a, node b){
return a.to > b.to;
}
const ll INF = 1e17;
}
void bitaro(int N, int M, int Q, int K, std::vector<int> A, std::vector<int> B,
std::vector<long long> C, std::vector<int> T, std::vector<int> X,
std::string s) {
map<pii, int> xi;
forR(i, K){
xi.insert({{A[X[i]], B[X[i]]}, i});
xi.insert({{B[X[i]], A[X[i]]}, i});
}
vector<vector<edge>> adj(N);
map<pii, int> ei;
forR(i, M){
int cxi = -1;
if(xi.count({A[i], B[i]})){
cxi = xi[{A[i], B[i]}];
}
adj[A[i]].push_back({B[i], cxi, C[i]});
adj[B[i]].push_back({A[i], cxi, C[i]});
ei[{A[i], B[i]}] = i;
ei[{B[i], A[i]}] = i;
}
forR(i, Q){
string curInfo = s.substr(K * i, K);
vector<ll> dis(N, INF);
vector<bool> vis(N);
vector<int> pre(N);
priority_queue<node> dij;
dij.push({0, 0});
dis[0] = 0;
while(!dij.empty()){
auto [cur, len] = dij.top();
dij.pop();
if(!vis[cur]){
vis[cur] = true;
for(auto [to, ind, el] : adj[cur]){
if(ind == -1 || curInfo[ind] == '1'){
el = ind == -1 ? el : 0;
if(len + el < dis[to]){
dis[to] = len + el;
pre[to] = cur;
dij.push({to, dis[to]});
}
}
}
}
}
vector<int> pth;
for(int j = T[i]; j != 0; j = pre[j]) pth.push_back(j);
pth.push_back(0);
reverse(all(pth));
for(int j : pth) cerr << j << ' ';
cerr << '\n';
vector<int> ret;
forR(j, (int) pth.size() - 1) ret.push_back(ei[{pth[j], pth[j+1]}]);
answer(ret);
}
}
Compilation message
Aoi.cpp: In function 'bool {anonymous}::operator<({anonymous}::pii, {anonymous}::pii)':
Aoi.cpp:12:64: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
12 | bool operator <(pii a, pii b) {return a.a < b.a || a.a == b.a && a.b < b.b;}
| ~~~~~~~~~~~^~~~~~~~~~~~
Bitaro.cpp: In function 'bool {anonymous}::operator<({anonymous}::pii, {anonymous}::pii)':
Bitaro.cpp:12:64: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
12 | bool operator <(pii a, pii b) {return a.a < b.a || a.a == b.a && a.b < b.b;}
| ~~~~~~~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
23 ms |
6360 KB |
Partially correct |
2 |
Correct |
0 ms |
776 KB |
Output is correct |
3 |
Partially correct |
48 ms |
7008 KB |
Partially correct |
4 |
Partially correct |
167 ms |
6900 KB |
Partially correct |
5 |
Partially correct |
43 ms |
7032 KB |
Partially correct |
6 |
Partially correct |
69 ms |
7032 KB |
Partially correct |
7 |
Partially correct |
41 ms |
6936 KB |
Partially correct |
8 |
Partially correct |
69 ms |
6860 KB |
Partially correct |
9 |
Partially correct |
142 ms |
6812 KB |
Partially correct |
10 |
Correct |
36 ms |
6672 KB |
Output is correct |
11 |
Partially correct |
41 ms |
6844 KB |
Partially correct |
12 |
Correct |
101 ms |
6892 KB |
Output is correct |
13 |
Partially correct |
49 ms |
6836 KB |
Partially correct |
14 |
Partially correct |
40 ms |
7000 KB |
Partially correct |
15 |
Correct |
122 ms |
6828 KB |
Output is correct |
16 |
Correct |
31 ms |
6520 KB |
Output is correct |
17 |
Partially correct |
253 ms |
7112 KB |
Partially correct |
18 |
Partially correct |
275 ms |
7088 KB |
Partially correct |
19 |
Partially correct |
44 ms |
7992 KB |
Partially correct |
20 |
Partially correct |
40 ms |
8036 KB |
Partially correct |
21 |
Partially correct |
45 ms |
7984 KB |
Partially correct |
22 |
Partially correct |
53 ms |
8000 KB |
Partially correct |
23 |
Partially correct |
42 ms |
7980 KB |
Partially correct |
24 |
Partially correct |
56 ms |
7988 KB |
Partially correct |
25 |
Partially correct |
218 ms |
7156 KB |
Partially correct |
26 |
Partially correct |
216 ms |
7060 KB |
Partially correct |
27 |
Correct |
0 ms |
776 KB |
Output is correct |
28 |
Partially correct |
57 ms |
7324 KB |
Partially correct |
29 |
Partially correct |
81 ms |
4924 KB |
Partially correct |
30 |
Correct |
77 ms |
7468 KB |
Output is correct |
31 |
Correct |
39 ms |
7348 KB |
Output is correct |
32 |
Partially correct |
47 ms |
7348 KB |
Partially correct |
33 |
Correct |
49 ms |
6968 KB |
Output is correct |
34 |
Partially correct |
109 ms |
7600 KB |
Partially correct |
35 |
Correct |
78 ms |
7860 KB |
Output is correct |
36 |
Partially correct |
82 ms |
7584 KB |
Partially correct |
37 |
Partially correct |
69 ms |
4124 KB |
Partially correct |
38 |
Partially correct |
193 ms |
5228 KB |
Partially correct |
39 |
Partially correct |
186 ms |
5396 KB |
Partially correct |
40 |
Correct |
25 ms |
4584 KB |
Output is correct |
41 |
Partially correct |
52 ms |
7684 KB |
Partially correct |
42 |
Partially correct |
52 ms |
7888 KB |
Partially correct |
43 |
Correct |
83 ms |
7956 KB |
Output is correct |
44 |
Correct |
31 ms |
7880 KB |
Output is correct |
45 |
Partially correct |
75 ms |
4136 KB |
Partially correct |
46 |
Partially correct |
89 ms |
4792 KB |
Partially correct |
47 |
Correct |
104 ms |
4932 KB |
Output is correct |
48 |
Correct |
0 ms |
776 KB |
Output is correct |
49 |
Correct |
0 ms |
784 KB |
Output is correct |
50 |
Partially correct |
22 ms |
6328 KB |
Partially correct |
51 |
Partially correct |
3 ms |
1304 KB |
Partially correct |
52 |
Partially correct |
1 ms |
784 KB |
Partially correct |
53 |
Partially correct |
25 ms |
6424 KB |
Partially correct |
54 |
Partially correct |
15 ms |
4324 KB |
Partially correct |
55 |
Partially correct |
28 ms |
5208 KB |
Partially correct |
56 |
Partially correct |
36 ms |
7352 KB |
Partially correct |
57 |
Partially correct |
41 ms |
7568 KB |
Partially correct |
58 |
Partially correct |
33 ms |
6076 KB |
Partially correct |
59 |
Partially correct |
44 ms |
7888 KB |
Partially correct |
60 |
Partially correct |
41 ms |
7580 KB |
Partially correct |
61 |
Partially correct |
49 ms |
7864 KB |
Partially correct |
62 |
Partially correct |
44 ms |
7248 KB |
Partially correct |
63 |
Partially correct |
49 ms |
7860 KB |
Partially correct |
64 |
Correct |
24 ms |
6844 KB |
Output is correct |
65 |
Partially correct |
26 ms |
5292 KB |
Partially correct |
66 |
Partially correct |
31 ms |
8144 KB |
Partially correct |
67 |
Partially correct |
26 ms |
5368 KB |
Partially correct |
68 |
Partially correct |
33 ms |
8216 KB |
Partially correct |
69 |
Correct |
0 ms |
776 KB |
Output is correct |
70 |
Correct |
0 ms |
784 KB |
Output is correct |
71 |
Correct |
1 ms |
788 KB |
Output is correct |
72 |
Partially correct |
13 ms |
3864 KB |
Partially correct |
73 |
Partially correct |
23 ms |
4636 KB |
Partially correct |
74 |
Partially correct |
26 ms |
4540 KB |
Partially correct |
75 |
Correct |
16 ms |
4592 KB |
Output is correct |
76 |
Correct |
0 ms |
784 KB |
Output is correct |
77 |
Correct |
36 ms |
7236 KB |
Output is correct |
78 |
Partially correct |
38 ms |
7284 KB |
Partially correct |
79 |
Correct |
41 ms |
7272 KB |
Output is correct |
80 |
Correct |
0 ms |
784 KB |
Output is correct |
81 |
Partially correct |
41 ms |
6908 KB |
Partially correct |
82 |
Partially correct |
39 ms |
6816 KB |
Partially correct |
83 |
Partially correct |
47 ms |
6844 KB |
Partially correct |