답안 #698070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698070 2023-02-12T08:17:52 Z Tien_Noob The short shank; Redemption (BOI21_prison) C++17
0 / 100
1 ms 340 KB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e6;
int n, T, cnt[N + 1], deg[N + 1], a[N + 1], d;
struct FenwickTree
{
    int tree[N + 1];
    void add(int pos, int val)
    {
        pos = min(pos, val);
        for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
        {
            tree[pos] = val;
        }
    }
    int get(int pos)
    {
        int ret = 0;
        for (; pos <= n; pos |= pos + 1)
        {
            ret = max(ret, tree[pos]);
        }
        return ret;
    }
} tree;
int res;
void read()
{
    cin >> n >> d >> T;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
        if (a[i] > T)
        {
            int pre = tree.get(i);
            if (pre == 0)
            {
                ++res;
            }
            else
            {
                --cnt[deg[pre]];
                ++deg[pre];
                ++cnt[deg[pre]];
            }
        }
        else
        {
            tree.add(T + i - a[i], i);
        }
    }
}
void solve()
{
    for (int i = n; i >= 1; -- i)
    {
        while(cnt[i] > 0 && d > 0)
        {
            res += i;
            --cnt[i];
            --d;
        }
    }
    cout << n - res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Compilation message

prison.cpp: In function 'int main()':
prison.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -