Submission #3447572
Source Code Expand
#include <bits/stdc++.h> using namespace std; int n, zw[2], now = 0, nx, ny, ans = 0; int a[2005] = {0}; void solve(); int calc(int x); int main() { cin >> n >> zw[0] >> zw[1]; for(int i = 0; i < n; ++i) cin >> a[i]; solve(); cout << ans << endl; return 0; } void solve() { int xy = 0, nextn = 0; nx = ny = -1; while(1) { nextn = n - 1; now = abs(zw[!xy] - a[n - 1]); if(!xy) ans = max(now, ans); else ans = min(now, ans); for(int i = n - 2; i > max(nx, ny); --i) { int p = abs(a[n - 1] - a[i]); if(!xy) { if(p < ans) break; else if(p >= ans) nextn = i; } else { if(p > ans) break; else if(p < now) nextn = i; } } if(nextn == n - 1) break; if(nextn == n - 2) { ans = abs(a[n - 1] - a[n - 2]); break; } if(!xy) nx = nextn; else ny = nextn; } }
Submission Info
Submission Time | |
---|---|
Task | D - ABS |
User | m_tsubasa |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 998 Byte |
Status | AC |
Exec Time | 2 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_0, example_1, example_2, example_3 |
All | example_0, example_1, example_2, example_3, one_0, one_1, one_2, one_3, one_4, one_5, one_6, one_7, rand_0, rand_1, rand_10, rand_11, rand_12, rand_13, rand_14, rand_15, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_0 | AC | 1 ms | 256 KB |
example_1 | AC | 1 ms | 256 KB |
example_2 | AC | 1 ms | 256 KB |
example_3 | AC | 1 ms | 256 KB |
one_0 | AC | 1 ms | 256 KB |
one_1 | AC | 1 ms | 256 KB |
one_2 | AC | 1 ms | 256 KB |
one_3 | AC | 1 ms | 256 KB |
one_4 | AC | 1 ms | 256 KB |
one_5 | AC | 1 ms | 256 KB |
one_6 | AC | 1 ms | 256 KB |
one_7 | AC | 1 ms | 256 KB |
rand_0 | AC | 2 ms | 256 KB |
rand_1 | AC | 1 ms | 256 KB |
rand_10 | AC | 2 ms | 256 KB |
rand_11 | AC | 2 ms | 256 KB |
rand_12 | AC | 2 ms | 256 KB |
rand_13 | AC | 2 ms | 256 KB |
rand_14 | AC | 2 ms | 256 KB |
rand_15 | AC | 1 ms | 256 KB |
rand_2 | AC | 2 ms | 256 KB |
rand_3 | AC | 2 ms | 256 KB |
rand_4 | AC | 2 ms | 256 KB |
rand_5 | AC | 2 ms | 256 KB |
rand_6 | AC | 2 ms | 256 KB |
rand_7 | AC | 2 ms | 256 KB |
rand_8 | AC | 2 ms | 256 KB |
rand_9 | AC | 2 ms | 256 KB |