#include "Aoi.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
struct edge
{
int to, id;
long long dist;
edge(int to, int id, long long dist) : to(to), id(id), dist(dist) {}
};
class BigInt
{
const long long base = 1ll << 32;
vector<long long> v;
void update()
{
for (int i = 0; i < v.size(); i++)
{
long long r = v[i] / base;
if (r == 0)
continue;
v[i] %= base;
if (i == v.size() - 1)
{
v.push_back(r);
}
else
{
v[i + 1] += r;
}
}
}
public:
BigInt &operator+=(const long long t)
{
if (v.empty())
{
v.push_back(t);
}
else
{
v.front() += t;
}
update();
return *this;
}
BigInt &operator*=(const long long t)
{
for (int i = 0; i < v.size(); i++)
{
v[i] *= t;
}
update();
return *this;
}
BigInt &operator/=(const long long t)
{
long long m = 0;
for (int i = v.size() - 1; i >= 0; i--)
{
m *= base;
v[i] += m;
m = v[i] % t;
v[i] /= t;
}
return *this;
}
long long operator%(const long long t)
{
long long m = 0;
for (int i = v.size() - 1; i >= 0; i--)
{
m *= base;
m += v[i];
m %= t;
}
return m;
}
string encode(int d)
{
string t;
for (int i = 0; i < d; i++)
{
int k = i / 32;
if (k >= v.size())
{
t += '0';
}
else
{
int m = i % 32;
t += '0' + ((v[k] >> m) & 1);
}
}
return t;
}
};
} // namespace
string aoi(int N, int M, int Q, int K, vector<int> A, vector<int> B,
vector<long long> C, vector<int> T, vector<int> X)
{
vector<vector<edge>> edges(N);
for (int i = 0; i < M; i++)
{
edges[A[i]].emplace_back(B[i], i, C[i]);
edges[B[i]].emplace_back(A[i], i, C[i]);
}
vector<long long> dist(N, -1);
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
greater<pair<long long, int>>>
pq;
pq.push({0, 0});
while (!pq.empty())
{
int x = pq.top().second;
long long d = pq.top().first;
pq.pop();
if (dist[x] != -1)
{
continue;
}
dist[x] = d;
for (edge e : edges[x])
{
pq.push({d + e.dist, e.to});
}
}
vector<int> map_edges(M, -1);
for (int i = 0; i < K; i++)
{
map_edges[X[i]] = i;
}
vector<int> first_query_num(K, Q); // ãã‚Œãžã‚Œã®éš ã•ã‚Œã¦ã„る辺ã«ã¤ã„ã¦ï¼Œãã®è¾ºã‚’通éŽã™ã‚‹æœ€åˆã®ã‚¯ã‚¨ãƒªç•ªå·
vector<int> last_edge_num(Q, K); // ãã‚Œãžã‚Œã®ã‚¯ã‚¨ãƒªã«ã¤ã„ã¦ï¼Œãれ以å‰ã®ã‚¯ã‚¨ãƒªã§é€šã£ãŸè¾ºã®ã†ã¡æœ€ã‚‚最後ã«é€šã‚‹ï¼ˆéš ã•ã‚ŒãŸï¼‰è¾ºã®ç•ªå·
for (int i = 0; i < Q; i++)
{
int p = T[i];
while (p != 0)
{
for (edge e : edges[p])
{
if (dist[e.to] + e.dist == dist[p])
{
int m_id = map_edges[e.id];
if (m_id != -1)
{
if (last_edge_num[i] == K &&
first_query_num[m_id] != Q)
{
last_edge_num[i] = m_id;
}
if (first_query_num[m_id] == Q)
{
first_query_num[m_id] = i;
}
}
p = e.to;
break;
}
}
}
}
string s;
BigInt bi;
for (int i = 0; i < K; i++)
{
bi *= Q + 1;
bi += first_query_num[i];
}
for (int i = 1; i < Q; i++)
{
bi *= K + 1;
bi += last_edge_num[i];
}
return bi.encode(1350);
}
#include "Bitaro.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
struct edge
{
int to, id;
long long dist;
edge(int to, int id, long long dist) : to(to), id(id), dist(dist) {}
};
class BigInt
{
const long long base = 1ll << 32;
vector<long long> v;
void update()
{
for (int i = 0; i < v.size(); i++)
{
long long r = v[i] / base;
if (r == 0)
continue;
v[i] %= base;
if (i == v.size() - 1)
{
v.push_back(r);
}
else
{
v[i + 1] += r;
}
}
}
public:
BigInt &operator+=(const long long t)
{
if (v.empty())
{
v.push_back(t);
}
else
{
v.front() += t;
}
update();
return *this;
}
BigInt &operator*=(const long long t)
{
for (int i = 0; i < v.size(); i++)
{
v[i] *= t;
}
update();
return *this;
}
BigInt &operator/=(const long long t)
{
long long m = 0;
for (int i = v.size() - 1; i >= 0; i--)
{
m *= base;
v[i] += m;
m = v[i] % t;
v[i] /= t;
}
return *this;
}
long long operator%(const long long t)
{
long long m = 0;
for (int i = v.size() - 1; i >= 0; i--)
{
m *= base;
m += v[i];
m %= t;
}
return m;
}
string encode(int d)
{
string t;
for (int i = 0; i < d; i++)
{
int k = i / 32;
if (k >= v.size())
{
t += '0';
}
else
{
int m = i % 32;
t += '0' + ((v[k] >> m) & 1);
}
}
return t;
}
};
BigInt decode(string s, int d)
{
BigInt bi;
for (int i = d - 1; i >= 0; i--)
{
bi *= 2;
if (s[i] == '1')
{
bi += 1;
}
}
return bi;
}
} // namespace
void bitaro(int N, int M, int Q, int K, vector<int> A, vector<int> B,
vector<long long> C, vector<int> T, vector<int> X, string s)
{
BigInt bi = decode(s, 1350);
vector<int> first_query_num(K, Q);
vector<int> last_edge_num(Q, K);
for (int i = Q - 1; i >= 1; i--)
{
last_edge_num[i] = bi % (K + 1);
bi /= K + 1;
}
for (int i = K - 1; i >= 0; i--)
{
first_query_num[i] = bi % (Q + 1);
bi /= Q + 1;
}
vector<vector<int>> answers(Q);
for (int i = 0; i < Q; i++)
{
vector<vector<edge>> edges(N);
for (int j = 0; j < K; j++)
{
if (first_query_num[j] == i)
{
C[X[j]] = 1;
}
else
{
C[X[j]] = 20'000'000'000'000'000;
}
}
for (int j = 0; j < M; j++)
{
edges[A[j]].emplace_back(B[j], j, C[j]);
edges[B[j]].emplace_back(A[j], j, C[j]);
}
vector<long long> dist(N, -1);
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
greater<pair<long long, int>>>
pq;
int start = 0;
if (last_edge_num[i] != K)
{
int q = first_query_num[last_edge_num[i]];
for (int j = 0;; j++)
{
answers[i].push_back(answers[q][j]);
start ^= A[answers[q][j]] ^ B[answers[q][j]];
if (answers[q][j] == X[last_edge_num[i]])
{
break;
}
}
}
pq.emplace(0, start);
while (!pq.empty())
{
int x = pq.top().second;
long long d = pq.top().first;
pq.pop();
if (dist[x] != -1)
{
continue;
}
dist[x] = d;
for (edge e : edges[x])
{
pq.emplace(d + e.dist, e.to);
}
}
int p = T[i];
vector<int> v;
while (p != start)
{
for (edge e : edges[p])
{
if (dist[e.to] + e.dist == dist[p])
{
v.push_back(e.id);
p = e.to;
break;
}
}
}
reverse(v.begin(), v.end());
for (int t : v)
{
answers[i].push_back(t);
}
answer(answers[i]);
}
}
Compilation message
Aoi.cpp: In member function 'void {anonymous}::BigInt::update()':
Aoi.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
Aoi.cpp:25:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if (i == v.size() - 1)
| ~~^~~~~~~~~~~~~~~
Aoi.cpp: In member function '{anonymous}::BigInt& {anonymous}::BigInt::operator*=(long long int)':
Aoi.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
Aoi.cpp: In member function 'std::string {anonymous}::BigInt::encode(int)':
Aoi.cpp:88:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | if (k >= v.size())
| ~~^~~~~~~~~~~
Bitaro.cpp: In member function 'void {anonymous}::BigInt::update()':
Bitaro.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
Bitaro.cpp:25:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if (i == v.size() - 1)
| ~~^~~~~~~~~~~~~~~
Bitaro.cpp: In member function '{anonymous}::BigInt& {anonymous}::BigInt::operator*=(long long int)':
Bitaro.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
Bitaro.cpp: In member function 'std::string {anonymous}::BigInt::encode(int)':
Bitaro.cpp:88:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | if (k >= v.size())
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
102 ms |
6760 KB |
Output is correct |
2 |
Correct |
1 ms |
1028 KB |
Output is correct |
3 |
Correct |
95 ms |
4664 KB |
Output is correct |
4 |
Correct |
77 ms |
5116 KB |
Output is correct |
5 |
Correct |
103 ms |
4928 KB |
Output is correct |
6 |
Correct |
94 ms |
4632 KB |
Output is correct |
7 |
Correct |
98 ms |
4676 KB |
Output is correct |
8 |
Correct |
92 ms |
4688 KB |
Output is correct |
9 |
Correct |
78 ms |
4916 KB |
Output is correct |
10 |
Correct |
33 ms |
4552 KB |
Output is correct |
11 |
Correct |
105 ms |
4668 KB |
Output is correct |
12 |
Correct |
83 ms |
4696 KB |
Output is correct |
13 |
Correct |
89 ms |
4636 KB |
Output is correct |
14 |
Correct |
105 ms |
4636 KB |
Output is correct |
15 |
Correct |
76 ms |
4836 KB |
Output is correct |
16 |
Correct |
16 ms |
4376 KB |
Output is correct |
17 |
Correct |
84 ms |
4972 KB |
Output is correct |
18 |
Correct |
87 ms |
4980 KB |
Output is correct |
19 |
Correct |
110 ms |
6436 KB |
Output is correct |
20 |
Correct |
97 ms |
6312 KB |
Output is correct |
21 |
Correct |
105 ms |
6144 KB |
Output is correct |
22 |
Correct |
106 ms |
6092 KB |
Output is correct |
23 |
Correct |
71 ms |
6196 KB |
Output is correct |
24 |
Correct |
100 ms |
6048 KB |
Output is correct |
25 |
Correct |
112 ms |
6048 KB |
Output is correct |
26 |
Correct |
93 ms |
5804 KB |
Output is correct |
27 |
Correct |
1 ms |
784 KB |
Output is correct |
28 |
Correct |
94 ms |
4940 KB |
Output is correct |
29 |
Correct |
55 ms |
3572 KB |
Output is correct |
30 |
Correct |
91 ms |
5304 KB |
Output is correct |
31 |
Correct |
45 ms |
4916 KB |
Output is correct |
32 |
Correct |
99 ms |
4996 KB |
Output is correct |
33 |
Correct |
94 ms |
4808 KB |
Output is correct |
34 |
Correct |
99 ms |
5248 KB |
Output is correct |
35 |
Correct |
94 ms |
5104 KB |
Output is correct |
36 |
Correct |
102 ms |
5028 KB |
Output is correct |
37 |
Correct |
17 ms |
3128 KB |
Output is correct |
38 |
Correct |
40 ms |
3968 KB |
Output is correct |
39 |
Correct |
46 ms |
3868 KB |
Output is correct |
40 |
Correct |
10 ms |
3356 KB |
Output is correct |
41 |
Correct |
125 ms |
6432 KB |
Output is correct |
42 |
Correct |
66 ms |
6404 KB |
Output is correct |
43 |
Correct |
112 ms |
6508 KB |
Output is correct |
44 |
Correct |
22 ms |
6060 KB |
Output is correct |
45 |
Correct |
22 ms |
3068 KB |
Output is correct |
46 |
Correct |
34 ms |
3496 KB |
Output is correct |
47 |
Correct |
37 ms |
3600 KB |
Output is correct |
48 |
Correct |
0 ms |
776 KB |
Output is correct |
49 |
Correct |
1 ms |
776 KB |
Output is correct |
50 |
Correct |
55 ms |
6720 KB |
Output is correct |
51 |
Correct |
6 ms |
1296 KB |
Output is correct |
52 |
Correct |
1 ms |
776 KB |
Output is correct |
53 |
Correct |
95 ms |
6712 KB |
Output is correct |
54 |
Correct |
52 ms |
4388 KB |
Output is correct |
55 |
Correct |
73 ms |
4284 KB |
Output is correct |
56 |
Correct |
73 ms |
6328 KB |
Output is correct |
57 |
Correct |
109 ms |
6320 KB |
Output is correct |
58 |
Correct |
94 ms |
4748 KB |
Output is correct |
59 |
Correct |
124 ms |
6340 KB |
Output is correct |
60 |
Correct |
114 ms |
5776 KB |
Output is correct |
61 |
Correct |
115 ms |
6260 KB |
Output is correct |
62 |
Correct |
108 ms |
5484 KB |
Output is correct |
63 |
Correct |
121 ms |
6412 KB |
Output is correct |
64 |
Correct |
20 ms |
4792 KB |
Output is correct |
65 |
Correct |
47 ms |
3828 KB |
Output is correct |
66 |
Correct |
52 ms |
6260 KB |
Output is correct |
67 |
Correct |
53 ms |
3788 KB |
Output is correct |
68 |
Correct |
54 ms |
6376 KB |
Output is correct |
69 |
Correct |
0 ms |
776 KB |
Output is correct |
70 |
Correct |
0 ms |
776 KB |
Output is correct |
71 |
Correct |
2 ms |
776 KB |
Output is correct |
72 |
Correct |
26 ms |
2872 KB |
Output is correct |
73 |
Correct |
56 ms |
3352 KB |
Output is correct |
74 |
Correct |
56 ms |
3344 KB |
Output is correct |
75 |
Correct |
11 ms |
3316 KB |
Output is correct |
76 |
Correct |
0 ms |
784 KB |
Output is correct |
77 |
Correct |
104 ms |
5456 KB |
Output is correct |
78 |
Correct |
97 ms |
5044 KB |
Output is correct |
79 |
Correct |
89 ms |
5100 KB |
Output is correct |
80 |
Correct |
0 ms |
776 KB |
Output is correct |
81 |
Correct |
103 ms |
4584 KB |
Output is correct |
82 |
Correct |
97 ms |
4644 KB |
Output is correct |
83 |
Correct |
93 ms |
4568 KB |
Output is correct |