# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
64997 | patrikpavic2 | Dango Maker (JOI18_dango_maker) | C++17 | 3 ms | 688 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int N = 105;
const int M = N * N / 5;
vector < int > v[M];
bool bio[M], ty[M];
int mat[M], kk[N][N][2];
char s[N][N];
int n, m, edg, cnt = 1;
int dfs( int node ) {
if( bio[ node ] ) return 0;
bio[ node ] = 1;
for(int sus : v[node]){
if( mat[ sus ] == -1 || dfs( mat[ sus ]) ) {
mat[ sus ] = node;
return 1;
}
}
return 0;
}
int matching( ) {
int sol = 0;
memset( mat, -1, sizeof( mat ) );
for( int i = 1; i < cnt; i++) {
if(ty[i]) continue;
sol += dfs(i);
}
return sol;
}
int main(){
memset(s, '.', sizeof(s));
scanf("%d%d", &n, &m);
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
scanf(" %c", &s[i][j]);
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(s[i][j] != 'G') continue;
int kol = 0;
if(s[i - 1][j] == 'R' && s[i + 1][j] == 'W'){
kk[i][j][0] = cnt;
cnt++;kol++;
}
if(s[i][j - 1] == 'R' && s[i][j + 1] == 'W'){
ty[cnt] = 1;
kk[i][j][1] = cnt;
cnt++;kol++;
}
if(kol == 2){
v[cnt - 1].push_back(cnt - 2);
v[cnt - 2].push_back(cnt - 1);
edg++;
}
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(i + 1 < n && j + 1 < m && s[i][j] == 'R' && s[i + 1][j] == 'G' && s[i][j + 1] == 'G' && s[i + 2][j] == 'W' && s[i][j + 2] == 'W'){
v[kk[i + 1][j][0]].push_back(kk[i][j + 1][1]);
v[kk[i][j + 1][1]].push_back(kk[i + 1][j][0]);
//printf("AT %d %d\n", i, j);
edg++;
}
if(i > 2 && j > 2 && s[i][j] == 'W' && s[i - 1][j] == 'G' && s[i][j - 1] == 'G' && s[i - 2][j] == 'R' && s[i][j - 2] == 'R'){
v[kk[i - 1][j][0]].push_back(kk[i][j - 1][1]);
v[kk[i][j - 1][1]].push_back(kk[i - 1][j][0]);
//printf("AT %d %d\n", i, j);
edg++;
}
}
}
//printf("EDG %d\n", edg);
printf("%d\n", cnt - matching() - 1);
return 0;
}
컴파일 시 표준 에러 (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... |