Submission #199837

#TimeUsernameProblemLanguageResultExecution timeMemory
199837MercenaryMiners (IOI07_miners)C++14
43 / 100
61 ms13176 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 2e5 + 5; int n; string s; int dp[maxn][16]; int tmp[2]; int cnt[2][3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n >> s; for(int i = 0 ; i < n ; ++i){ if(s[i] == 'M')s[i] = 0; else if(s[i] == 'F')s[i] = 1; else s[i] = 2; } memset(dp,-123,sizeof dp); dp[0][0] = 0; for(int i = 0 ; i < n ; ++i){ for(int j = 0 ; j < 16 ; ++j){ if(dp[i][j] >= 0){ memset(tmp,0,sizeof tmp);memset(cnt,0,sizeof cnt); for(int t = 0 ; t <= 3; ++t){ bool cur = (j & (1 << t)); if(tmp[cur]++ < 2 && i - 1 - t >= 0)cnt[cur][s[i - 1 - t]]++; } int cal[2] = {0,0}; cnt[0][s[i]]++;cnt[1][s[i]]++; for(int t = 0 ; t < 3 ; ++t){ if(cnt[0][t])cal[0]++; if(cnt[1][t])cal[1]++; } for(int t = 0 ; t < 2 ; ++t){ dp[i + 1][(j << 1 | t) & 15] = max(dp[i + 1][(j << 1 | t) & 15] , dp[i][j] + cal[t]); } } } } cout << *max_element(dp[n],dp[n]+16); }

Compilation message (stderr)

miners.cpp: In function 'int main()':
miners.cpp:46:78: warning: array subscript has type 'char' [-Wchar-subscripts]
                     if(tmp[cur]++ < 2 && i - 1 - t >= 0)cnt[cur][s[i - 1 - t]]++;
                                                                              ^
miners.cpp:49:28: warning: array subscript has type 'char' [-Wchar-subscripts]
                 cnt[0][s[i]]++;cnt[1][s[i]]++;
                            ^
miners.cpp:49:43: warning: array subscript has type 'char' [-Wchar-subscripts]
                 cnt[0][s[i]]++;cnt[1][s[i]]++;
                                           ^
miners.cpp:29:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
miners.cpp:30:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   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...