답안 #1053878

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053878 2024-08-11T19:40:37 Z VMaksimoski008 케이크 (CEOI14_cake) C++17
15 / 100
2000 ms 4568 KB
#include <bits/stdc++.h>
//#define int long long

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 3e5 + 5;

struct SegTree {

};

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n, s, q;
    cin >> n >> s;
    int id = n + 1;

    vector<ll> v(n+1), v2;
    for(int i=1; i<=n; i++) cin >> v[i];
    for(int i=1; i<=n; i++) v2.push_back(i);
    sort(v2.begin(), v2.end(), [&](int a, int b) {
        return v[a] > v[b];
    });

    while(v2.size() > 10) v2.pop_back();
    for(int i=0; i<v2.size(); i++) v[v2[i]] = 1e6 - i;

    cin >> q;
    while(q--) {
        char t;
        cin >> t;

        if(t == 'F') {
            int p;
            cin >> p;

            if(p == s) {
                cout << 0 << '\n';
                continue;
            }

            int l=s, r=s, ans=0;
            while(l != p && r != p) {
                ans++;
                if(l - 1 == 0) r++;
                else if(r + 1 > n) l--;
                else if(v[l-1] < v[r+1]) l--;
                else r++;
            }

            cout << ans << '\n';
        } else {
            int a, b;
            cin >> a >> b;
            
            vector<ll> v3;
            for(int i=0; i<v2.size(); i++)
                if(a != v2[i]) v3.push_back(v2[i]);
            v2 = v3;

            v2.insert(v2.begin() + b - 1, a);
            
            if(v2.size() == 1) {
                v[v2.back()] = id++;
                v2.pop_back();
            }

            for(int i=0; i<v2.size(); i++) v[v2[i]] = 1e6 - i;
        }
    }

    return 0;
}

Compilation message

cake.cpp: In function 'int main()':
cake.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=0; i<v2.size(); i++) v[v2[i]] = 1e6 - i;
      |                  ~^~~~~~~~~~
cake.cpp:65:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |             for(int i=0; i<v2.size(); i++)
      |                          ~^~~~~~~~~~
cake.cpp:76:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |             for(int i=0; i<v2.size(); i++) v[v2[i]] = 1e6 - i;
      |                          ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 7 ms 348 KB Output is correct
5 Correct 117 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2033 ms 600 KB Time limit exceeded
2 Execution timed out 2013 ms 600 KB Time limit exceeded
3 Execution timed out 2071 ms 604 KB Time limit exceeded
4 Correct 90 ms 604 KB Output is correct
5 Execution timed out 2074 ms 1140 KB Time limit exceeded
6 Execution timed out 2044 ms 1032 KB Time limit exceeded
7 Execution timed out 2071 ms 1240 KB Time limit exceeded
8 Correct 103 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2072 ms 2268 KB Time limit exceeded
2 Execution timed out 2044 ms 2264 KB Time limit exceeded
3 Execution timed out 2019 ms 2264 KB Time limit exceeded
4 Correct 0 ms 344 KB Output is correct
5 Execution timed out 2040 ms 4564 KB Time limit exceeded
6 Execution timed out 2036 ms 4564 KB Time limit exceeded
7 Execution timed out 2041 ms 4564 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 295 ms 592 KB Output is correct
2 Correct 566 ms 604 KB Output is correct
3 Execution timed out 2059 ms 1504 KB Time limit exceeded
4 Execution timed out 2035 ms 1500 KB Time limit exceeded
5 Correct 489 ms 592 KB Output is correct
6 Execution timed out 2052 ms 2008 KB Time limit exceeded
7 Execution timed out 2068 ms 968 KB Time limit exceeded
8 Execution timed out 2023 ms 2264 KB Time limit exceeded
9 Execution timed out 2031 ms 4564 KB Time limit exceeded
10 Correct 1626 ms 1616 KB Output is correct
11 Execution timed out 2068 ms 1144 KB Time limit exceeded
12 Execution timed out 2068 ms 4056 KB Time limit exceeded
13 Execution timed out 2049 ms 4568 KB Time limit exceeded