제출 #1274741

#제출 시각아이디문제언어결과실행 시간메모리
1274741baotoan655JJOOII 2 (JOI20_ho_t2)C++20
100 / 100
12 ms7488 KiB
#include <bits/stdc++.h> #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } using namespace std; const int N = 2e5 + 5; int n, k; int con(char x) { if(x == 'J') return 0; else if(x == 'O') return 1; return 2; } int pref[3][N]; int best[3][N]; int dp[N][3]; void cal(int pr[], int *bst) { int j = 1; for(int i = 1; i <= n; ++i) { while(j < i && pr[i] - pr[j] >= k) ++j; if(pr[i] - pr[j - 1] >= k) bst[i] = j; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); file("A") else file("task"); cin >> n >> k; for(int i = 1; i <= n; ++i) { for(int j = 0; j < 3; ++j) pref[j][i] = pref[j][i - 1]; char x; cin >> x; int c = con(x); pref[c][i]++; } memset(best, -0x3f, sizeof best); for(int c = 0; c < 3; ++c) cal(pref[c], best[c]); memset(dp, -0x3f, sizeof dp); for(int i = 1; i <= n; ++i) if(best[0][i] >= 1) dp[i][0] = best[0][i]; for(int j = 1; j < 3; ++j) { for(int i = 1; i <= n; ++i) if(best[j][i] >= 1) dp[i][j] = dp[best[j][i] - 1][j - 1]; for(int i = 1; i <= n; ++i) dp[i][j] = max(dp[i][j], dp[i - 1][j]); } // cout << best[1][7] << '\n'; // cout << dp[7][1] << '\n'; int ans = n + 1; for(int i = 1; i <= n; ++i) ans = min(ans, i - dp[i][2] + 1 - 3 * k); if(ans > n) ans = -1; cout << ans << '\n'; return 0; }

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

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:28:5: note: in expansion of macro 'file'
   28 |     file("A") else file("task");
      |     ^~~~
ho_t2.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:28:5: note: in expansion of macro 'file'
   28 |     file("A") else file("task");
      |     ^~~~
ho_t2.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:28:20: note: in expansion of macro 'file'
   28 |     file("A") else file("task");
      |                    ^~~~
ho_t2.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:28:20: note: in expansion of macro 'file'
   28 |     file("A") else file("task");
      |                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...