Submission #1051147

# Submission time Handle Problem Language Result Execution time Memory
1051147 2024-08-09T20:53:47 Z beaconmc Spy 3 (JOI24_spy3) C++17
0 / 100
28 ms 8888 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]);
    vector<ll> order;

    for (auto&i : T) sus.insert(i);
    ll pos = 0;
    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 cur = curq;
        FOR(i,0,Q) if (T[i] == curq) order.push_back(i);
        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];
        }
        pos++;
    }

    FOR(i,0,Q){
        FOR(p, 0, 5){
            if (order[i] & (1<<p))ans += '1';
            else ans += '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> order;
    ll newcur =0 ;
    FOR(i,0,Q*5){
        newcur += (s[i]=='1')* (1<<(i%5));
        if (i%5==4) order.push_back(newcur),newcur=0;
    }

    vector<ll> mins;
    ll cur = 0;

    FOR(i,Q*5,s.size()){
        cur += (s[i]=='1') * (1<<(i%5));
        if (i%5==4) mins.push_back(cur),cur=0;
    }
    vector<int> ans[16];



    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[order[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[order[i]];
        
        while (prevs[cur][1] != -1){
            stuff.push_back(prevs[cur][1]);
            cur = prevs[cur][0];
        }

        reverse(stuff.begin(), stuff.end());


        ans[order[i]] = stuff;



    }
    FOR(i,0,Q){

        answer(ans[i]);
    }

}

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++)
......
   35 |     FOR(i,Q*5,s.size()){
      |         ~~~~~~~~~~~~~~           
Bitaro.cpp:35:5: note: in expansion of macro 'FOR'
   35 |     FOR(i,Q*5,s.size()){
      |     ^~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 8888 KB Output is correct
2 Incorrect 2 ms 2316 KB Wrong Answer [4]
3 Halted 0 ms 0 KB -