제출 #842923

#제출 시각아이디문제언어결과실행 시간메모리
842923anha3k25cvpLinear Garden (IOI08_linear_garden)C++14
75 / 100
567 ms65536 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define dl double #define st first #define nd second #define II pair <int, int> using namespace std; const int N = 5 + 1e5; const int inf = 7 + 1e9; int main() { #define TASKNAME "" ios_base :: sync_with_stdio (0); cin.tie (0); if ( fopen( TASKNAME".inp", "r" ) ) { freopen (TASKNAME".inp", "r", stdin); freopen (TASKNAME".out", "w", stdout); } int n, m; string s; cin >> n >> m >> s; vector <int> a(n + 1, 0); for (int i = 1; i <= n; i ++) a[i] = s[i - 1] == 'P'; vector <vector <vector <int>>> f(n + 1, vector <vector <int>> (5, vector <int> (5, 0))); for (int mi = 0; mi <= 4; mi ++) for (int ma = mi; ma <= 4; ma ++) { vector <vector <vector <int>>> g(n + 1, vector <vector <int>> (5, vector <int> (5, 0))); g[0][mi][ma] = 1; for (int num = 0; num < n; num ++) for (int i = 0; i <= 4; i ++) for (int j = i; j <= 4; j ++) { if (i > 0) { int i_ = min(i - 1, 1), j_ = max(j - 1, 1); g[num + 1][i_][j_] = (g[num + 1][i_][j_] + g[num][i][j]) % m; } if (j < 4) { int i_ = min(i + 1, 3), j_ = max(j + 1, 3); g[num + 1][i_][j_] = (g[num + 1][i_][j_] + g[num][i][j]) % m; } } for (int num = 0; num <= n; num ++) for (int i = 0; i <= 4; i ++) for (int j = i; j <= 4; j ++) f[num][mi][ma] = (f[num][mi][ma] + g[num][i][j]) % m; } int mi = 2, ma = 2, ans = 1; for (int i = 1; i <= n; i ++) { if (a[i] && mi > 0) { int mi_ = min(mi - 1, 1), ma_ = max(ma - 1, 1); ans = (ans + f[n - i][mi_][ma_]) % m; } if (!a[i]) { mi = min(mi - 1, 1); ma = max(ma - 1, 1); } else { mi = min(mi + 1, 3); ma = max(ma + 1, 3); } if (mi < 0 || ma > 4) break; } cout << ans; return 0; }

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

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:19:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
linear_garden.cpp:20:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen (TASKNAME".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...
#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...
#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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...