답안 #1076956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076956 2024-08-26T19:49:06 Z bleahbleah Tortoise (CEOI21_tortoise) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
 
#define _ << " " <<
 
const int MAXN = 5e5 + 5;
const int off = 1 << 19;
const int inf = 1e9;
 
 #define int long long
 
int a[MAXN];
int l[MAXN];
int r[MAXN];
int before[MAXN];
 
unordered_map<int, int> specialChair;
 
typedef pair<int, int> pii;
  
bool possible(multiset<int> s)
{
    int last = -1, timer = 0;
    for(auto x : s)
    {
        if(last == -1)
        {
            timer += x - 1;
        }
        else
        {
            if(l[last] != l[x] || r[last] != r[x])
                timer += x - last;
            else timer += min(last - l[last] + x - l[last], r[last] - last + r[last] - x);
        }
        if(timer > 2 * (x - 1))
        {
            return 0;
        }
        last = x;
        //cerr << timer << '\n';
    }
    //cerr << '\n';
    //for(auto x: s) cerr << x << ' '; cerr << '\n';
    //cerr << "ok\n";
    return 1;
}

long long sum;
 
multiset<int> TT;
 
void solve(int x, int d, int type) {
    int cnt = 0;
    while(a[x] > 0) {
         TT.insert(x);
         if(possible(TT)) {
           a[x] --;
           sum --;
           cnt ++;
         }
         else {
            TT.erase(TT.find(x));
            break;
         }
    }
}
 
signed main() {
    int n; cin >> n;
 
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] != -1) sum += a[i];
    }
 
    int tmp = -1;
    for (int i = 0; i < n; ++i) {
        if (a[i] == -1) {
            tmp = i;
        }
        l[i] = tmp;
    }
    tmp = -1;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] == -1) {
            tmp = i;
        }
        r[i] = tmp;
    }
 
 
    
    vector<pair<int, pii>> candidates;
    for (int i = 0; i < n; ++i) {
        if (a[i] > 0) {
            if (r[i] != -1) {
                candidates.push_back({r[i] - i, {i, 1}});
            }
            if (l[i] != -1) {
                candidates.push_back({i - l[i], {i, 0}});
            }
        }
    }
    sort(candidates.begin(), candidates.end());
 
    for (auto candidate : candidates) {
        int x = candidate.second.first;
        int d = candidate.first;
        int type = candidate.second.second;
 
        solve(x, d, type);
    }
 
   sum =0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] != -1) sum += a[i];
    }
    cout << sum << '\n';
 
}
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -