Submission #308091

# Submission time Handle Problem Language Result Execution time Memory
308091 2020-09-30T03:20:47 Z caoash Lightning Conductor (POI11_pio) C++17
81 / 100
1000 ms 11208 KB
#include <bits/stdc++.h> 
using namespace std;

using ll = long long;

using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

const int MX = 500005;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;

int a[MX];
int pre[MX], suf[MX];
int n;

int main(){
    scanf("%d" , &n) ;
	for(int i = 0 ; i < n ; ++i)
		scanf("%d" , &a[i]) ;
    for (int i = 0; i < n; ++i) {
        int j, k, c;
        if (i != 0) {
            for (j = i - 1, k = 1, c = 1; j >= 0; j -= k, k += 2, ++c) {
                suf[j] = max(suf[j], a[i] + c);
            }
        }
        if (i != n - 1) {
            for (j = i + 1, k = 1, c = 1; j < n; j += k, k += 2, ++c) {
                pre[j] = max(pre[j], a[i] + c);
            }
        }
    }
    for (int i = 1; i < n; ++i) {
        pre[i] = max(pre[i - 1], pre[i]);
    }
    for (int i = n - 2; i >= 0; --i) {
        suf[i] = max(suf[i + 1], suf[i]);
    }
    for (int i = 0; i < n; ++i) {
        printf("%d\n", max(0, max(pre[i], suf[i]) - a[i]));
    }
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |     scanf("%d" , &n) ;
      |     ~~~~~^~~~~~~~~~~
pio.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |   scanf("%d" , &a[i]) ;
      |   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 1400 KB Output is correct
2 Correct 50 ms 1400 KB Output is correct
3 Correct 53 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 1912 KB Output is correct
2 Correct 95 ms 1912 KB Output is correct
3 Correct 95 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 4088 KB Output is correct
2 Correct 320 ms 3960 KB Output is correct
3 Correct 314 ms 4592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 622 ms 7988 KB Output is correct
2 Correct 593 ms 5892 KB Output is correct
3 Correct 612 ms 8056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1060 ms 11208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 8824 KB Time limit exceeded
2 Halted 0 ms 0 KB -