# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1051136 |
2024-08-09T20:39:01 Z |
beaconmc |
Spy 3 (JOI24_spy3) |
C++17 |
|
8 ms |
8536 KB |
#include "Aoi.h"
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
namespace {
const ll INF = 10000000000000000;
const ll maxn = 10005;
vector<vector<ll>> edges[maxn];
vector<ll> prevs[maxn];
ll dists[maxn];
bool visited[maxn];
} // 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) {
string ans;
FOR(i,0,M){
edges[A[i]].push_back({B[i], C[i], i});
edges[B[i]].push_back({A[i], C[i], i});
}
FOR(k,0,maxn) dists[k] = INF, prevs[k] = {-1, -1}, visited[k] = 0;
priority_queue<vector<ll>> pq;
dists[0] = 0;
pq.push({0, 0});
vector<ll> mins(K);
FOR(i,0,K) mins[i] = 17;
set<ll> sus;
set<ll> orig;
FOR(i,0,K) orig.insert(X[i]);
for (auto&i : X) sus.insert(i);
while (sus.size()){
ll curq = -1;
while (pq.size()){
vector<ll> node = pq.top();
if (sus.count(node[1])){
curq = node[1];
sus.erase(node[1]);
break;
}
pq.pop();
node[0] = -node[0];
if (node[0] != dists[node[1]]) continue;
for (auto&i : edges[node[1]]){
if (dists[i[0]] > node[0] + i[1]){
prevs[i[0]] = {node[1], i[2]};
dists[i[0]] = node[0] + i[1];
pq.push({-dists[i[0]], i[0]});
}
}
}
ll pos = 0;
FOR(i,0,Q) if (T[i] == curq) pos = i;
ll cur = curq;
while (prevs[cur][1] != -1){
if (orig.count(prevs[cur][1])) mins[prevs[cur][1]] = min(mins[prevs[cur][1]], pos);
cur = prevs[cur][0];
}
}
FOR(i,0,K){
FOR(p, 0, 5){
if (mins[i] & (1<<p))ans += '1';
else ans += '0';
}
}
return ans;
}
#include "Bitaro.h"
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
namespace {
const ll INF = 10000000000000000;
const ll maxn = 10005;
vector<vector<ll>> edges[maxn];
vector<ll> prevs[maxn];
ll dists[maxn];
bool visited[maxn];
} // 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) {
vector<ll> mins;
ll cur = 0;
FOR(i,0,s.size()){
cur += (s[i]=='1') * (1<<(i%5));
if (i%5==4) mins.push_back(cur),cur=0;
}
FOR(i,0,M){
edges[A[i]].push_back({B[i], C[i], i});
edges[B[i]].push_back({A[i], C[i], i});
}
unordered_set<ll> idk;
FOR(i,0,Q){
FOR(k,0,maxn) dists[k] = INF, prevs[k] = {-1, -1}, visited[k] = 0;
FOR(j,0,K) if (mins[j] == i) idk.insert(X[j]);
unordered_set<ll> idkman;
for (auto&i : X) idkman.insert(i);
FOR(i,0,maxn){
for (auto&j : edges[i]){
if (idk.count(j[2])) j[1] = 1;
else if (idkman.count(j[2])) j[1] = INF;
}
}
priority_queue<vector<ll>> pq;
dists[0] = 0;
pq.push({0, 0});
while (pq.size()){
vector<ll> node = pq.top();
if (node[1] == T[i]) break;
pq.pop();
node[0] = -node[0];
if (node[0] != dists[node[1]]) continue;
for (auto&i : edges[node[1]]){
if (dists[i[0]] > node[0] + i[1]){
prevs[i[0]] = {node[1], i[2]};
dists[i[0]] = node[0] + i[1];
pq.push({-dists[i[0]], i[0]});
}
}
}
vector<int> stuff;
ll cur = T[i];
while (prevs[cur][1] != -1){
stuff.push_back(prevs[cur][1]);
cur = prevs[cur][0];
}
reverse(stuff.begin(), stuff.end());
answer(stuff);
}
}
Compilation message
Bitaro.cpp: In function 'void bitaro(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<long long int>, std::vector<int>, std::vector<int>, std::string)':
Bitaro.cpp:5:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
27 | FOR(i,0,s.size()){
| ~~~~~~~~~~~~
Bitaro.cpp:27:5: note: in expansion of macro 'FOR'
27 | FOR(i,0,s.size()){
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
8536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |