답안 #547658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547658 2022-04-11T08:31:43 Z tengiz05 The Potion of Great Power (CEOI20_potion) C++17
38 / 100
1320 ms 262144 KB
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif

using namespace std;

/*


6 5 11 4
2 42 1000 54 68 234
0 1
2 0
3 4
3 5
3 5
1 3
5 3
0 5
3 0
1 3
3 5
0 3 4 26
3 0 8 0
0 5 5 1000000000
3 0 11 14


*/

namespace sOlUTiON {
    constexpr int N = 1E5, M = 2E5;
    int n, D;
    int h[N];
    vector<int> f[N];
    vector<vector<int>> a[N], con[N];
};
using namespace sOlUTiON;

void init(int _N, int _D, int H[]) {
    n = _N;
    D = _D;
    for (int i = 0; i < n; i++) {
        con[i].push_back({});
        a[i].push_back({});
        f[i].push_back(0);
        h[i] = H[i];
    }
}

void curseChanges(int U, int A[], int B[]) {
    for (int i = 0; i < U; i++) {
        int u = A[i];
        int v = B[i];
        
        {
            vector<int> b = a[u].back(), c = con[u].back(), w;
            int j = 0;
            while (j < int(b.size()) && b[j] < h[v])
                w.push_back(b[j++]);
            
            auto p = find(c.begin(), c.end(), v);
            if (p != c.end()) {
                j++;
                c.erase(p);
            } else {
                c.push_back(v);
                w.push_back(h[v]);
            }
            
            while (j < int(b.size()))
                w.push_back(b[j++]);
            
            a[u].push_back(w);
            con[u].push_back(c);
        }
        {
            vector<int> b = a[v].back(), c = con[v].back(), w;
            int j = 0;
            while (j < int(b.size()) && b[j] < h[u])
                w.push_back(b[j++]);
            
            auto p = find(c.begin(), c.end(), u);
            if (p != c.end()) {
                j++;
                c.erase(p);
            } else {
                c.push_back(u);
                w.push_back(h[u]);
            }
            
            while (j < int(b.size()))
                w.push_back(b[j++]);
            
            a[v].push_back(w);
            con[v].push_back(c);
        }
        
        f[u].push_back(i + 1);
        f[v].push_back(i + 1);
    }
}

int question(int x, int y, int v) {
    int p1 = upper_bound(f[x].begin(), f[x].end(), v) - f[x].begin() - 1;
    int p2 = upper_bound(f[y].begin(), f[y].end(), v) - f[y].begin() - 1;
    
    int ans = 1E9;
    
    for (int i = 0; i < int(a[x][p1].size()); i++) {
        for (int j = 0; j < int(a[y][p2].size()); j++) {
            ans = min(ans, abs(a[x][p1][i] - a[y][p2][j]));
        }
    }
    
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7708 KB Output is correct
2 Correct 6 ms 7632 KB Output is correct
3 Correct 5 ms 7632 KB Output is correct
4 Correct 32 ms 17736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 709 ms 73308 KB Output is correct
2 Correct 580 ms 73344 KB Output is correct
3 Correct 420 ms 81096 KB Output is correct
4 Runtime error 449 ms 262144 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 612 ms 73244 KB Output is correct
2 Runtime error 395 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 11088 KB Output is correct
2 Correct 58 ms 11892 KB Output is correct
3 Correct 91 ms 11848 KB Output is correct
4 Correct 1150 ms 21036 KB Output is correct
5 Correct 1320 ms 18496 KB Output is correct
6 Correct 60 ms 11216 KB Output is correct
7 Correct 717 ms 19400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7296 KB Output is correct
2 Correct 7 ms 7708 KB Output is correct
3 Correct 6 ms 7632 KB Output is correct
4 Correct 5 ms 7632 KB Output is correct
5 Correct 32 ms 17736 KB Output is correct
6 Correct 709 ms 73308 KB Output is correct
7 Correct 580 ms 73344 KB Output is correct
8 Correct 420 ms 81096 KB Output is correct
9 Runtime error 449 ms 262144 KB Execution killed with signal 9
10 Halted 0 ms 0 KB -