제출 #473729

#제출 시각아이디문제언어결과실행 시간메모리
473729Lam_lai_cuoc_doiBigger segments (IZhO19_segments)C++17
0 / 100
1 ms204 KiB
#define task "PARTITION" #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; using ll = long long; using ld = long double; template <class T> void read(T &x) { x = 0; register int c; while ((c = getchar()) && (c > '9' || c < '0')) ; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; } constexpr int N = 5e5 + 5; constexpr int Inf = 1e9 + 7; int n, pre[N], ans[N]; ll a[N]; void Read() { cin >> n; //read(n); for (int i = 1; i <= n; ++i) cin >> a[i]; //read(a[i]); reverse(a + 1, a + n + 1); for (int i = 1; i <= n; ++i) a[i] += a[i - 1]; } void Sub_1() { vector<vector<int>> dp(n + 5, vector<int>(n + 5, -Inf)); dp[0][0] = 0; for (int i = 1; i <= n; ++i) { for (int j = i - 1, t = i - 2; j >= 0; --j) { if (t >= j) --t; while (t >= 0 && a[i] - a[j] >= a[j] - a[t]) --t; dp[i][j] = max(dp[i][j + 1], dp[j][t + 1] + 1); } } cout << dp[n][0]; } void Greedy() { for (int i = 1; i <= n; ++i) { pre[i] = max(pre[i], pre[i - 1]); ans[i] = ans[pre[i]] + 1; int j = lower_bound(a + 1, a + n + 1, a[i] * 2 - a[pre[i]]) - a; pre[j] = max(pre[j], i); } cout << ans[n]; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } Read(); if (n <= 1000) Sub_1(); else Greedy(); }

컴파일 시 표준 에러 (stderr) 메시지

segments.cpp: In function 'void read(T&)':
segments.cpp:17:18: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   17 |     register int c;
      |                  ^
segments.cpp: In function 'int32_t main()':
segments.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(task ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(task ".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...