답안 #701398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701398 2023-02-21T07:40:50 Z Do_you_copy Lightning Conductor (POI11_pio) C++17
91 / 100
98 ms 15876 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back

using namespace std;
using ll = long long;
using pii = pair <int, int>;

const int maxN = 5e5 + 10;
const int inf = 0x3f3f3f3f;
//const int Mod =
int n;
int a[maxN];
int pre[maxN];
int suf[maxN];
void Init(){
    cin >> n;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    int maxx = 0;
    for (int i = 1; i <= n; ++i){
        if (a[i] <= maxx) continue;
        maxx = a[i];
        for (int j = 1; i + (j - 1) * (j - 1) + 1 <= n; ++j){
            pre[i + (j - 1) * (j - 1) + 1] = max(pre[i + (j - 1) * (j - 1) + 1], a[i] + j);
        }
    }
    maxx = 0;
    for (int i = n; i >= 1; --i){
        if (a[i] <= maxx) continue;
        maxx = a[i];
        for (int j = 1; i - (j - 1) * (j - 1) - 1 > 0; ++j){
            suf[i - (j - 1) * (j - 1) - 1] = max(suf[i - (j - 1) * (j - 1) - 1], a[i] + j);
        }
    }

    for (int i = 1; i <= n; ++i){
        pre[i] = max(pre[i], pre[i - 1]);
    }
    for (int i = n; i >= 1; --i){
        suf[i] = max(suf[i], suf[i + 1]);
    }
    for (int i = 1; i <= n; ++i){
        cout << max({suf[i], pre[i], a[i]}) - a[i] << "\n";
    }
}

#define taskname "test"
signed main(){
    faster
    if (fopen(taskname ".inp", "r")){
        freopen(taskname ".inp", "r", stdin);
        freopen(taskname ".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    if (fopen("timeout.txt", "r")){
        ofstream timeout("timeout.txt");
        cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
        timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
        timeout.close();
    }
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pio.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1900 KB Output is correct
2 Incorrect 12 ms 1324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2900 KB Output is correct
2 Correct 18 ms 2764 KB Output is correct
3 Correct 18 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 6292 KB Output is correct
2 Correct 39 ms 5916 KB Output is correct
3 Correct 41 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 84 ms 11228 KB Output is correct
2 Correct 60 ms 9248 KB Output is correct
3 Correct 63 ms 9960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 15876 KB Output is correct
2 Correct 84 ms 13048 KB Output is correct
3 Correct 87 ms 14040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 13456 KB Output is correct
2 Correct 84 ms 13008 KB Output is correct
3 Correct 85 ms 14000 KB Output is correct