Submission #761917

#TimeUsernameProblemLanguageResultExecution timeMemory
761917dxz05Linear Garden (IOI08_linear_garden)C++17
0 / 100
28 ms65536 KiB
//#pragma GCC optimize("Ofast,O3,unroll-loops") //#pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bpc(x) __builtin_popcount(x) #define bpcll(x) __builtin_popcountll(x) #define MP make_pair //#define endl '\n' mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); typedef long long ll; const int N = 1e6 + 3e2; int n, MOD; int dp[1000000][2][3][3][5]; string s; int calc(int ind, bool small, int mx, int mn, int bal){ mx = max(mx, bal); mn = min(mn, bal); if (mx - mn > 2) return 0; if (ind == n){ return 1; } int &res = dp[ind][small][mx][2 + mn][2 + bal]; if (res != -1) return res; res = 0; if (small){ res += calc(ind + 1, true, mx, mn, bal - 1); res += calc(ind + 1, true, mx, mn, bal + 1); } else { if (s[ind] == 'L'){ res += calc(ind + 1, false, mx, mn, bal - 1); } else { res += calc(ind + 1, true, mx, mn, bal - 1); res += calc(ind + 1, false, mx, mn, bal + 1); } } res %= MOD; return res; } void solve(){ cin >> n >> MOD >> s; memset(dp, -1, sizeof(dp)); cout << calc(0, false, 0, 0, 0) << endl; } int main(){ clock_t startTime = clock(); ios_base::sync_with_stdio(false); #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int test_cases = 1; // cin >> test_cases; for (int test = 1; test <= test_cases; test++){ // cout << (solve() ? "YES" : "NO") << endl; solve(); } #ifdef LOCAL cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl; #endif return 0; }

Compilation message (stderr)

linear_garden.cpp: In function 'int main()':
linear_garden.cpp:67:13: warning: unused variable 'startTime' [-Wunused-variable]
   67 |     clock_t startTime = clock();
      |             ^~~~~~~~~
#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...