# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
522229 | blue | Kamenčići (COCI21_kamencici) | C++17 | 0 ms | 204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
string s;
cin >> s;
s = " " + s;
vector<int> red(1+n);
for(int i = 1; i <= n; i++) red[i] = (s[i] == 'C');
int I = 1;
int J = n;
int dp[1+n+1][1+n+1];
/*
if the stones in play currently are [i, j] and both players have played optimally, what is the number
of stones 1 has?
*/
dp[1][n] = 0;
for(int j = n-1; j >= 1; j--)
{
dp[1][j] = dp[1][j+1] + ((j+1) % 2 == n % 2) * red[j+1];
}
for(int i = 2; i <= n; i++)
{
dp[i][n] = dp[i-1][n] + ((i-1) % 2 == n % 2) * red[i-1];
}
for(int d = n-1; d >= 0; d--)
{
for(int i = 2; i+d < n; i++)
{
int j = i+d;
if((i+j+1) % 2 == (1+n) % 2) //player 1 moves
{
dp[i][j] = min(dp[i][j+1] + red[j+1], dp[i-1][j] + red[i-1]);
}
else
{
dp[i][j] = max(dp[i][j+1], dp[i-1][j]);
}
}
}
}
컴파일 시 표준 에러 (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... |