# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
261136 | stoyan_malinin | Miners (IOI07_miners) | C++14 | 854 ms | 1024 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<map>
#include<set>
using namespace std;
const int MAXN = 1e5 + 5;
int n;
int a[MAXN];
int configVal[45];
int transition[45][3];
vector <vector <int>> configs;
map <vector <int>, int> configCode;
void genConfigs(vector <int> v)
{
if(v.size()>3) return;
configCode[v] = configs.size();
configs.push_back(v);
for(int i = 0;i<3;i++)
{
v.push_back(i);
genConfigs(v);
v.pop_back();
}
}
void read()
{
cin >> n;
string input;
cin >> input;
for(int i = 0;i<n;i++)
{
if(input[i]=='M') a[i+1] = 0;
else if(input[i]=='B') a[i+1] = 1;
else if(input[i]=='F') a[i+1] = 2;
}
}
int extendConfig(int cInd, int ext)
{
vector <int> v = configs[cInd];
v.push_back(ext);
if(v.size()>3) v.erase(v.begin());
return configCode[v];
}
void init()
{
genConfigs(vector <int>{});
for(int i = 0;i<configs.size();i++)
{
for(int ext = 0;ext<3;ext++)
{
transition[i][ext] = extendConfig(i, ext);
}
}
for(int i = 0;i<configs.size();i++)
{
set <int> s;
for(int f: configs[i]) s.insert(f);
configVal[i] = s.size();
}
}
int dp[2][45][45];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
read();
init();
for(int i = 0;i<configs.size();i++)
{
for(int j = 0;j<configs.size();j++)
{
dp[0][i][j] = -5*MAXN;
}
}
dp[0][0][0] = 0;
for(int i = 1;i<=n;i++)
{
for(int c1 = 0;c1<configs.size();c1++)
for(int c2 = 0;c2<configs.size();c2++)
dp[i&1][c1][c2] = -5*MAXN;
for(int c1 = 0;c1<configs.size();c1++)
{
for(int c2 = 0;c2<configs.size();c2++)
{
dp[i&1][ transition[c1][ a[i] ] ][c2] = max(dp[i&1][ transition[c1][ a[i] ] ][c2],
dp[(i&1)^1][c1][c2] + configVal[ transition[c1][ a[i] ] ]);
dp[i&1][c1][ transition[c2][ a[i] ] ] = max(dp[i&1][c1][ transition[c2][ a[i] ] ],
dp[(i&1)^1][c1][c2] + configVal[ transition[c2][ a[i] ] ]);
}
}
}
int answer = 0;
for(int c1 = 0;c1<configs.size();c1++)
{
for(int c2 = 0;c2<configs.size();c2++)
{
answer = max(answer, dp[n&1][c1][c2]);
}
}
cout << answer << '\n';
}
컴파일 시 표준 에러 (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... |