Submission #669351

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



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

    for(int i=0; i<n; i++){
        sts[i].push_back(s);
        st[i].push_back(-1);
    }

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


}

void curseChanges(int u, int a[], int b[]){
    for(int i=0; i<u; i++){
        adj[a[i]].push_back({h[b[i]], b[i]});
        adj[b[i]].push_back({h[a[i]], a[i]});
    }

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


   for(int i=0; i<N; i++){
        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].back();
        
        int pos=mp[{x, y}];
        if(ss[pos]==1) ss[pos]=0;
        else ss[pos]=1; 

        sts[x].push_back(ss);
        st[x].push_back(i);


        ss=sts[y].back();
        pos=mp[{y, x}];

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

        sts[y].push_back(ss);
        st[y].push_back(i);

    }
}


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

    int posx=0, posy=0;

   for(int i=0; i<st[x].size(); i++){
    if(st[x][i]<v) posx=i;
   }
       for(int i=0; i<st[y].size(); i++){
    if(st[y][i]<v) posy=i;
   }



    if(posx >= st[x].size() || posy <= 0 || st[x][posx] >= v) return 1e9;
    if(posy >= st[y].size() || posy <= 0 || st[y][posy] >= v) return 1e9;

    bitset sx = sts[x][posx], sy=sts[y][posy];
    int lx=0, ly=0;
      


    int ans=1e9;

    for(int i=0; i<sx.size(); i++){
      for(int l=0; l<sy.size(); l++){
        if(sx[i]==1&&sy[l]==1){
          ans=min(ans, abs(adj[x][i][0]-adj[y][l][0]));
        }
      }
    }

    return ans;

}

Compilation message

potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:38: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]
   38 |         for(int l=0; l<adj[i].size(); l++){
      |                      ~^~~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for(int i=0; i<st[x].size(); i++){
      |                 ~^~~~~~~~~~~~~
potion.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |        for(int i=0; i<st[y].size(); i++){
      |                     ~^~~~~~~~~~~~~
potion.cpp:82:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     if(posx >= st[x].size() || posy <= 0 || st[x][posx] >= v) return 1e9;
      |        ~~~~~^~~~~~~~~~~~~~~
potion.cpp:83:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     if(posy >= st[y].size() || posy <= 0 || st[y][posy] >= v) return 1e9;
      |        ~~~~~^~~~~~~~~~~~~~~
potion.cpp:92:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for(int i=0; i<sx.size(); i++){
      |                  ~^~~~~~~~~~
potion.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   93 |       for(int l=0; l<sy.size(); l++){
      |                    ~^~~~~~~~~~
potion.cpp:86:9: warning: unused variable 'lx' [-Wunused-variable]
   86 |     int lx=0, ly=0;
      |         ^~
potion.cpp:86:15: warning: unused variable 'ly' [-Wunused-variable]
   86 |     int lx=0, ly=0;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 198 ms 7888 KB Output is correct
2 Correct 192 ms 7788 KB Output is correct
3 Correct 203 ms 7900 KB Output is correct
4 Correct 121 ms 19484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3072 ms 96776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3009 ms 96776 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3037 ms 12600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7248 KB Output is correct
2 Correct 198 ms 7888 KB Output is correct
3 Correct 192 ms 7788 KB Output is correct
4 Correct 203 ms 7900 KB Output is correct
5 Correct 121 ms 19484 KB Output is correct
6 Execution timed out 3072 ms 96776 KB Time limit exceeded
7 Halted 0 ms 0 KB -