제출 #1123576

#제출 시각아이디문제언어결과실행 시간메모리
1123576kh0iLinear Garden (IOI08_linear_garden)C++17
100 / 100
801 ms1504 KiB
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif using ll = long long; using pii = pair<int, int>; #define F first #define S second #define sz(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll get_rand(ll l, ll r) { assert(l <= r); return uniform_int_distribution<ll> (l, r)(rng); } const int N = 1e6; int n; ll m; string s; ll f[2][3][3][5][2]; void solve(){ cin >> n >> m; cin >> s; for(int i = n; i >= 0; --i){ for(int mn = -2; mn <= 0; ++mn){ for(int mx = 0; mx <= 2; ++mx){ if(mx - mn > 2) continue; for(int sum = -2; sum <= 2; ++sum){ for(int lower = 0; lower <= 1; ++lower){ ll &cur = f[i & 1][mn + 2][mx][sum + 2][lower]; if(i == n){ cur = 1; continue; } if(sum + 1 <= 2 and max(mx, sum + 1) - mn <= 2){ cur += f[i & 1 ^ 1][mn + 2][max(mx, sum + 1)][sum + 1 + 2][lower | (s[i] == 'P')]; cur %= m; } if(lower or s[i] == 'P'){ if(sum - 1 >= -2 and mx - min(sum - 1, mn) <= 2){ cur += f[i & 1 ^ 1][min(sum - 1, mn) + 2][mx][sum - 1 + 2][lower]; cur %= m; } } // debug(i, mn, mx, sum, lower, cur); } } } } memset(f[i & 1 ^ 1], 0, sizeof(f[i & 1 ^ 1])); } cout << f[0][2][0][2][0]; } int32_t main() { cin.tie(nullptr)->sync_with_stdio(0); #define task "troll" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; // cin >> test; for(int i = 1; i <= test; ++i){ // cout << "Case #" << i << ": "; solve(); } #ifdef LOCAL cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n"; #endif return 0; }

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

linear_garden.cpp: In function 'int32_t main()':
linear_garden.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
linear_garden.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         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...
#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...