Submission #963493

# Submission time Handle Problem Language Result Execution time Memory
963493 2024-04-15T07:15:09 Z GrindMachine Two Transportations (JOI19_transportations) C++17
38 / 100
767 ms 48412 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(x) 42
#endif

/*



*/

#include "Azer.h"
#include <vector>

namespace {

    int n;
    vector<int> a;
    vector<vector<pii>> adj;
    priority_queue< pii, vector<pii>, greater<pii> > pq;
    vector<bool> vis;
    vector<int> ans;

    void send(){
        if(pq.empty()){
            rep(iter,30){
                SendA(0);
            }
        }
        else{
            auto [w,u] = pq.top();
            rep(i,20){
                int f = 1<<(20-i-1);
                int b = 0;
                if(w&f) b = 1;
                SendA(b);
            }
            rep(i,10){
                int f = 1<<(10-i-1);
                int b = 0;
                if(u&f) b = 1;
                SendA(b);
            }
        }
    }

}  // namespace

void InitA(int n_, int m, std::vector<int> U, std::vector<int> V,
           std::vector<int> C) {
    n = n_;
    adj.resize(n);
    ans.resize(n);
    vis.resize(n);

    rep(i,m) {
        int u = U[i], v = V[i], w = C[i];
        adj[u].pb({v,w}), adj[v].pb({u,w});        
    }

    vis[0] = 1;

    for(auto [v,w] : adj[0]){
        pq.push({w,v});
    }

    send();
}

void ReceiveA(bool x) {
    a.pb(x);
    if(sz(a) == 30){
        int w = 0;
        rep(i,20){
            w = (w<<1)|a[i];
        }
        int u = 0;
        for(int i = 20; i < 30; ++i){
            u = (u<<1)|a[i];
        }

        // cout << u << " " << w << endl;
        
        a.clear();

        if(u == 0) return;

        ans[u] = w;
        vis[u] = 1;
        for(auto [v,ww] : adj[u]){
            pq.push({w+ww,v});
        }

        while(!pq.empty()){
            auto [cost,u] = pq.top();
            if(vis[u]){
                pq.pop();
                conts;
            }
            break;
        }

        send();
    }
}

std::vector<int> Answer() {
    return ans;
}
#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(x) 42
#endif

/*



*/

#include "Baijan.h"
#include <vector>

const int inf1 = 1e9 + 5;

namespace {

    vector<vector<pii>> adj;
    vector<int> a;
    priority_queue< pii, vector<pii>, greater<pii> > pq;
    vector<bool> vis;
    vector<array<int,3>> sp_tree;
    vector<array<int,3>> edges;

    void send(int w, int u){
        rep(i,20){
            int f = 1<<(20-i-1);
            int b = 0;
            if(w&f) b = 1;
            SendB(b);
        }
        rep(i,10){
            int f = 1<<(10-i-1);
            int b = 0;
            if(u&f) b = 1;
            SendB(b);
        }
    }

}  // namespace

void InitB(int n, int m, std::vector<int> S, std::vector<int> T,
           std::vector<int> D) {
        
    adj.resize(n);
    vis.resize(n);

    rep(i,m){
        int u = S[i], v = T[i], w = D[i];
        adj[u].pb({v,w}), adj[v].pb({u,w});
    }

    vis[0] = 1;

    for(auto [v,w] : adj[0]){
        pq.push({w,v});
    }
}

void ReceiveB(bool y) {
    a.pb(y);
    if(sz(a) == 30){
        int w = 0;
        rep(i,20){
            w = (w<<1)|a[i];
        }
        int u = 0;
        for(int i = 20; i < 30; ++i){
            u = (u<<1)|a[i];
        }

        a.clear();

        if(u == 0){
            w = inf1;
        }

        // cout << u << " " << w << endl;

        while(!pq.empty()){
            auto [cost,u] = pq.top();
            if(vis[u]){
                pq.pop();
                conts;
            }
            
            break;
        }

        if(!pq.empty()){
            if(pq.top().ff < w){
                w = pq.top().ff;
                u = pq.top().ss;
            }
        }

        vis[u] = 1;

        for(auto [v,ww] : adj[u]){
            pq.push({w+ww,v});
        }

        send(w,u);
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 244 ms 792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 664 KB Output is correct
2 Runtime error 163 ms 556 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 172 ms 532 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 336 ms 788 KB Output is correct
2 Correct 311 ms 772 KB Output is correct
3 Correct 418 ms 13408 KB Output is correct
4 Correct 336 ms 664 KB Output is correct
5 Correct 367 ms 10016 KB Output is correct
6 Correct 288 ms 664 KB Output is correct
7 Correct 324 ms 824 KB Output is correct
8 Correct 304 ms 664 KB Output is correct
9 Correct 548 ms 23980 KB Output is correct
10 Correct 581 ms 24408 KB Output is correct
11 Correct 767 ms 48412 KB Output is correct
12 Correct 673 ms 47148 KB Output is correct
13 Correct 324 ms 1284 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 336 ms 788 KB Output is correct
2 Correct 311 ms 772 KB Output is correct
3 Correct 418 ms 13408 KB Output is correct
4 Correct 336 ms 664 KB Output is correct
5 Correct 367 ms 10016 KB Output is correct
6 Correct 288 ms 664 KB Output is correct
7 Correct 324 ms 824 KB Output is correct
8 Correct 304 ms 664 KB Output is correct
9 Correct 548 ms 23980 KB Output is correct
10 Correct 581 ms 24408 KB Output is correct
11 Correct 767 ms 48412 KB Output is correct
12 Correct 673 ms 47148 KB Output is correct
13 Correct 324 ms 1284 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Runtime error 162 ms 484 KB Execution killed with signal 13
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 336 ms 788 KB Output is correct
2 Correct 311 ms 772 KB Output is correct
3 Correct 418 ms 13408 KB Output is correct
4 Correct 336 ms 664 KB Output is correct
5 Correct 367 ms 10016 KB Output is correct
6 Correct 288 ms 664 KB Output is correct
7 Correct 324 ms 824 KB Output is correct
8 Correct 304 ms 664 KB Output is correct
9 Correct 548 ms 23980 KB Output is correct
10 Correct 581 ms 24408 KB Output is correct
11 Correct 767 ms 48412 KB Output is correct
12 Correct 673 ms 47148 KB Output is correct
13 Correct 324 ms 1284 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Runtime error 162 ms 484 KB Execution killed with signal 13
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 244 ms 792 KB Output isn't correct
2 Halted 0 ms 0 KB -