Submission #1008783

# Submission time Handle Problem Language Result Execution time Memory
1008783 2024-06-26T18:22:52 Z GrindMachine Spy 3 (JOI24_spy3) C++17
0 / 100
120 ms 13948 KB
#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;

        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]){
                while(!pq.empty()){
                    pq.pop();
                }
                
                for(auto [v,w] : adj[u]){
                    ll id = mp[{u,v}];
                    if(w == -1 and on_path[id]){
                        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){
            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);
    // }
}

Compilation message

Aoi.cpp:67:9: warning: 'int {anonymous}::function_example(int, int)' defined but not used [-Wunused-function]
   67 |     int function_example(int a, int b) { return a + b; }
      |         ^~~~~~~~~~~~~~~~
Aoi.cpp:65:9: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
   65 |     int variable_example = 0;
      |         ^~~~~~~~~~~~~~~~

Bitaro.cpp:67:9: warning: 'int {anonymous}::function_example(int, int)' defined but not used [-Wunused-function]
   67 |     int function_example(int a, int b) { return a + b; }
      |         ^~~~~~~~~~~~~~~~
Bitaro.cpp:65:9: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
   65 |     int variable_example = 0;
      |         ^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 120 ms 12588 KB Partially correct
2 Correct 0 ms 776 KB Output is correct
3 Runtime error 36 ms 13948 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -