제출 #270477

#제출 시각아이디문제언어결과실행 시간메모리
270477BeanZBali Sculptures (APIO15_sculpture)C++14
50 / 100
537 ms512 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 3e6 + 5; ll dp[2005], f[2005], a[2005], sum[2005]; ll ans = 0; bool chk(ll now, ll s){ for (int i = 41; i >= s; i--){ if ((ans & (1ll << i)) == 0){ if (now & (1ll << i)){ return false; } } } return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("VietCT.INP", "r")){ freopen("VietCT.INP", "r", stdin); freopen("VietCT.OUT", "w", stdout); } ll n, L, R; cin >> n >> L >> R; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i]; for (int s = 41; s >= 0; s--){ for (int i = 1; i <= n; i++){ f[i] = dp[i]; } for (int i = 1; i <= n; i++){ if (f[i] == -1) continue; f[i] = 1e9; for (int j = 0; j < i; j++){ if (f[j] == -1) continue; ll cost = sum[i] - sum[j]; if (chk(cost, s)){ f[i] = min(f[i], f[j] + 1); } } if (f[i] == 1e9) f[i] = -1; //cout << f[i] << " "; } //cout << endl; if (f[n] <= R && f[n] != -1){ for (int i = 1; i <= n; i++){ if (f[i] <= R) dp[i] = f[i]; else dp[i] = -1; } } else { ans = ans + (1ll << s); } } cout << ans; } /* 6 1 3 8 1 2 1 5 4 */

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

sculpture.cpp: In function 'int main()':
sculpture.cpp:24:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   24 |                 freopen("VietCT.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:25:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   25 |                 freopen("VietCT.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...