Submission #669373

# Submission time Handle Problem Language Result Execution time Memory
669373 2022-12-06T10:20:20 Z berr The Potion of Great Power (CEOI20_potion) C++17
0 / 100
748 ms 67072 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+30;
bitset<505> sts[N];
vector<array<int, 2>> adj[N];
map<array<int, 2>, int> mp;
bitset<505> s;
vector<int> h;


void init(int n, int d, int H[]){


    for(int i=0; i<n; i++){
        sts[i]=s;
        h.push_back(H[i]);
    }


}

void curseChanges(int u, int a[], int b[]){
    set<array<int, 2>> se;

    for(int i=0; i<u; i++){
      se.insert({a[i], b[i]});
    }
    for(auto x: se){

        adj[x[0]].push_back({h[x[1]], x[1]});
        adj[x[1]].push_back({h[x[0]], x[0]});
    }

    for(int i=0; i<N; i++){
        sort(adj[i].begin(), adj[i].end());
    }


   for(int i=0; i<N; i++){
      int count=0;

        for(int l=0; l<adj[i].size(); l++){
            mp[{i, adj[i][l][1]}]=l;
        }
    }

    for(int i=0; i<u; i++){
        int x=a[i], y=b[i];

        bitset ss=sts[x];
        
        int pos=mp[{x, y}];
        if(ss[pos]==1) ss[pos]=0;
        else ss[pos]=1; 

        sts[x]=ss;


        ss=sts[y];
        pos=mp[{y, x}];

        if(ss[pos]==1) ss[pos]=0;
        else ss[pos]=1; 

        sts[y]=ss;

    }
}


int question(int x, int y, int v){


    bitset sx = sts[x], sy=sts[y];
    int lx=0, ly=0;
    while(lx<sx.size() && sx[lx]==0) lx++;
    while(ly<sy.size() && sy[ly]==0) ly++;

    int ans=1e9;

    while(lx<sx.size() && ly < sy.size()){
        int vx=adj[x][lx][0];
        int vy=adj[y][ly][0];

        ans=min(ans, abs(vx-vy));

        if(vx < vy){
            lx ++;
            while(lx<sx.size() && sx[lx]==0) lx++;
        }
        else if(vx > vy){
            ly ++;
            while(ly<sy.size() && sy[ly]==0) ly++;
        }
        else break;

    }

    return ans;

}

Compilation message

potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int l=0; l<adj[i].size(); l++){
      |                      ~^~~~~~~~~~~~~~
potion.cpp:40:11: warning: unused variable 'count' [-Wunused-variable]
   40 |       int count=0;
      |           ^~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:76:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     while(lx<sx.size() && sx[lx]==0) lx++;
      |           ~~^~~~~~~~~~
potion.cpp:77:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     while(ly<sy.size() && sy[ly]==0) ly++;
      |           ~~^~~~~~~~~~
potion.cpp:81:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     while(lx<sx.size() && ly < sy.size()){
      |           ~~^~~~~~~~~~
potion.cpp:81:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     while(lx<sx.size() && ly < sy.size()){
      |                           ~~~^~~~~~~~~~~
potion.cpp:89:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             while(lx<sx.size() && sx[lx]==0) lx++;
      |                   ~~^~~~~~~~~~
potion.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   93 |             while(ly<sy.size() && sy[ly]==0) ly++;
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2640 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2888 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 575 ms 51688 KB Output is correct
2 Correct 535 ms 51612 KB Output is correct
3 Correct 162 ms 11552 KB Output is correct
4 Correct 748 ms 33340 KB Output is correct
5 Correct 606 ms 44200 KB Output is correct
6 Runtime error 468 ms 67072 KB Execution killed with signal 6
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 511 ms 51688 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 5528 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2640 KB Incorrect
2 Halted 0 ms 0 KB -