Submission #342475

# Submission time Handle Problem Language Result Execution time Memory
342475 2021-01-02T08:06:45 Z mario05092929 The Potion of Great Power (CEOI20_potion) C++11
17 / 100
3000 ms 30180 KB
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(),v.end()
#pragma gcc optimize("O3")
#pragma gcc optimize("Ofast")
#pragma gcc optimize("unroll-loops")
using namespace std;
const int INF = 1e9;
const int TMX = 1 << 18;
const long long llINF = 2e18;
const long long mod = 1e9+7;
const long long hashmod = 100003;
const int MAXN = 100000;
const int MAXM = 1000000;
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pi;
typedef pair <ll,ll> pl;
typedef vector <int> vec;
typedef vector <pi> vecpi;
typedef long long ll;
set <int> v[100005];
vec v2[100005];
int n,m,d,a[100005];
vecpi edge;


void init(int N, int D, int H[]) {
    n = N, d = D;
    for(int i = 0;i < n;i++) {
        a[i+1] = H[i];
    }
}

void curseChanges(int U, int A[], int B[]) {
    m = U;
    for(int i = 0;i < m;i++) edge.pb({A[i]+1,B[i]+1});
    for(pi i : edge) {
        if(v[i.x].find(i.y) != v[i.x].end()) v[i.x].erase(i.y), v[i.y].erase(i.x);
        else v[i.x].insert(i.y), v[i.y].insert(i.x);
    }
}

bool cmp(int x,int y) {return a[x] < a[y];}

int question(int x,int y,int day) {
    vec l,r;
    x++, y++;
    for(int i = 1;i <= n;i++) v[i].clear();
    for(pi i : edge) {
        if(!day) break;
        day--;
        if(v[i.x].find(i.y) != v[i.x].end()) v[i.x].erase(i.y), v[i.y].erase(i.x);
        else v[i.x].insert(i.y), v[i.y].insert(i.x);
    }
    for(int i : v[x]) l.pb(i);
    sort(all(l),cmp);
    for(int i : v[y]) r.pb(i);
    sort(all(r),cmp);
    int ans = INF,lp = 0,rp = 0;
    while(lp < l.size()&&rp < r.size()) {
        ans = min(ans,abs(a[l[lp]]-a[r[rp]]));
        if(a[l[lp]] < a[r[rp]]) lp++;
        else rp++;
    }
    return ans;
}

Compilation message

potion.cpp:6: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
    6 | #pragma gcc optimize("O3")
      | 
potion.cpp:7: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
    7 | #pragma gcc optimize("Ofast")
      | 
potion.cpp:8: warning: ignoring #pragma gcc optimize [-Wunknown-pragmas]
    8 | #pragma gcc optimize("unroll-loops")
      | 
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:63:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     while(lp < l.size()&&rp < r.size()) {
      |           ~~~^~~~~~~~~~
potion.cpp:63:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     while(lp < l.size()&&rp < r.size()) {
      |                          ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 7552 KB Output is correct
2 Correct 80 ms 7552 KB Output is correct
3 Correct 88 ms 7532 KB Output is correct
4 Correct 412 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3081 ms 30180 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3074 ms 30052 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3083 ms 8636 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 83 ms 7552 KB Output is correct
3 Correct 80 ms 7552 KB Output is correct
4 Correct 88 ms 7532 KB Output is correct
5 Correct 412 ms 8300 KB Output is correct
6 Execution timed out 3081 ms 30180 KB Time limit exceeded
7 Halted 0 ms 0 KB -