# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199840 | Mercenary | Miners (IOI07_miners) | C++14 | 173 ms | 100908 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = 1e5 + 5;
int n;
string s;
int dp[maxn][16][16];
int cnt[2][4];
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] = 1;
else if(s[i] == 'F')s[i] = 2;
else s[i] = 3;
}
memset(dp,-123,sizeof dp);
dp[0][0][0] = 0;
int res = 0;
for(int i = 0 ; i <= n ; ++i){
for(int j = 0 ; j < 16 ; ++j){
for(int k = 0 ; k < 16 ; ++k){
if(dp[i][j][k] >= 0){
if(i == n){
res = max(res,dp[i][j][k]);
continue;
}
memset(cnt,0,sizeof cnt);
cnt[0][j & 3]++;
cnt[0][(j >> 2) & 3]++;
cnt[1][k & 3]++;
cnt[1][(k >> 2) & 3]++;
int cal[2] = {0,0};
cnt[0][s[i]]++;cnt[1][s[i]]++;
for(int t = 1 ; t <= 3 ; ++t){
if(cnt[0][t])cal[0]++;
if(cnt[1][t])cal[1]++;
}
int cur = (j >> 2) | ((int)s[i] << 2);
dp[i + 1][cur][k] = max(dp[i + 1][cur][k],dp[i][j][k]+cal[0]);
cur = (k >> 2) | ((int)s[i] << 2);
dp[i + 1][j][cur] = max(dp[i + 1][j][cur],dp[i][j][k]+cal[1]);
}
}
}
}
cout << res;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |