# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1008788 | GrindMachine | Spy 3 (JOI24_spy3) | C++17 | 155 ms | 13012 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
/*
refs:
https://codeforces.com/blog/entry/127315?#comment-1131129
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "Aoi.h"
namespace {
int variable_example = 0;
int function_example(int a, int b) { return a + b; }
} // namespace
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) {
// n = #of nodes, m = #of edges
// A,B,C = edges of graph
// q = #of query cities
// T = query cities
// k = #of deleted edges
// X = ids of deleted edges
vector<pll> adj[n];
map<pll,ll> mp;
rep(i,m){
ll u = A[i], v = B[i], w = C[i];
adj[u].pb({v,w}), adj[v].pb({u,w});
mp[{u,v}] = mp[{v,u}] = i;
}
priority_queue<array<ll,3>,vector<array<ll,3>>,greater<array<ll,3>>> pq;
pq.push({0,0,-1});
vector<ll> par(n,-1);
vector<bool> vis(n);
while(!pq.empty()){
auto [dis,u,p] = pq.top();
pq.pop();
if(vis[u]) conts;
vis[u] = 1;
par[u] = p;
// cout << p << " " << u << endl;
for(auto [v,w] : adj[u]){
pq.push({dis+w,v,u});
}
}
string s = "";
rep(i,q){
ll u = T[i];
vector<ll> path;
while(u){
path.pb(u);
u = par[u];
}
path.pb(0);
vector<ll> edges;
rep(j,sz(path)-1){
pll px = {path[j],path[j+1]};
edges.pb(mp[px]);
}
sort(all(edges));
rep(j,k){
ll id = X[j];
if(binary_search(all(edges),id)){
s.pb('1');
}
else{
s.pb('0');
}
}
}
return s;
// variable_example++;
// variable_example = function_example(1, 2);
// std::string s(100, '0');
// s[0] = '1';
// return s;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
/*
refs:
https://codeforces.com/blog/entry/127315?#comment-1131129
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "Bitaro.h"
namespace {
int variable_example = 0;
int function_example(int a, int b) { return a + b; }
} // namespace
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) {
// n = #of nodes, m = #of edges
// A,B,C = edges of graph (edge weights of deleted edges = -1)
// q = #of query cities
// T = query cities
// k = #of deleted edges
// X = ids of deleted edges
// s = received string
vector<pll> adj[n];
map<pll,ll> mp;
rep(i,m){
ll u = A[i], v = B[i], w = C[i];
adj[u].pb({v,w}), adj[v].pb({u,w});
mp[{u,v}] = mp[{v,u}] = i;
}
ll ptr = 0;
rep(i,q){
vector<bool> spl(n);
vector<bool> on_path(m);
rep(j,k){
if(s[ptr] == '1'){
ll id = X[j];
on_path[id] = 1;
spl[A[id]] = spl[B[id]] = 1;
}
ptr++;
}
priority_queue<array<ll,3>,vector<array<ll,3>>,greater<array<ll,3>>> pq;
pq.push({0,0,-1});
vector<ll> par(n,-1);
vector<bool> vis(n);
while(!pq.empty()){
auto [dis,u,p] = pq.top();
pq.pop();
if(vis[u]) conts;
vis[u] = 1;
par[u] = p;
if(spl[u]){
ll cnt = 0;
for(auto [v,w] : adj[u]){
ll id = mp[{u,v}];
if(w == -1 and on_path[id]){
cnt++;
}
}
if(cnt){
while(!pq.empty()){
pq.pop();
}
for(auto [v,w] : adj[u]){
ll id = mp[{u,v}];
if(w == -1 and on_path[id]){
on_path[id] = 0;
pq.push({0,v,u});
}
}
conts;
}
}
for(auto [v,w] : adj[u]){
if(w == -1) conts;
pq.push({dis+w,v,u});
}
}
vector<ll> nodes;
ll u = T[i];
while(u){
assert(u != -1);
nodes.pb(u);
u = par[u];
}
nodes.pb(0);
reverse(all(nodes));
vector<int> ans;
rep(j,sz(nodes)-1){
pll px = {nodes[j],nodes[j+1]};
ans.pb(mp[px]);
}
answer(ans);
// trav(x,ans) cout << x << " ";
// cout << endl;
}
// variable_example++;
// variable_example = function_example(1, 2);
// for (int i = 0; i < q; i++) {
// std::vector<int> v(10);
// for (int j = 0; j < 10; j++) {
// v[j] = j;
// }
// answer(v);
// }
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |