Submission #99445

# Submission time Handle Problem Language Result Execution time Memory
99445 2019-03-04T06:44:02 Z psmao Dango Maker (JOI18_dango_maker) C++14
13 / 100
58 ms 48504 KB
#include <bits/stdc++.h>
using namespace std;

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 1001;

int n, m;
bool b[maxn*maxn], seen[maxn*maxn];
int s0, s1;
char a[maxn][maxn];
VI adj[maxn*maxn*2];

void link(int u, int v) {adj[u].pb(v);}
bool color(int x, int c=0)
{
	seen[x] = true;
	b[x] = c;
	if(c == 0) s0 ++; else s1 ++;
	for(auto p : adj[x]) 
		if(seen[p] && b[p] == c) return false;
		else if(!seen[p] && !color(p, c^1)) return false;
	return true;
}
int p(int x, int y){return (x-1)*m+y;}
int pp(int x, int y){return (x-1)*m+y+n*m;}
int main()
{
	#ifdef MPS
		fp("1.in","r",stdin);
		fp("1.out","w",stdout);
	#endif
	sf("%d%d",&n,&m);
	fo(i,1,n) sf("%s",a[i]+1);
	fo(i,1,n) fo(j,1,m) if(a[i][j] == 'R')
	{
		if(j+2 <= m && a[i][j+1] == 'G' && a[i][j+2] == 'W')
		{
			if(i>1 && i < n && a[i-1][j+1] == 'R' && a[i+1][j+1] == 'W') 
				link(p(i,j), pp(i-1,j+1));
			if(i>2 && a[i-2][j+2] == 'R' && a[i-1][j+2] == 'G') 
				link(p(i,j), pp(i-2,j+2));
			if(i <= n-2 && a[i+1][j] == 'G' && a[i+2][j] == 'W') 
				link(p(i,j), pp(i,j));
		}
		if(i+2 <= n && a[i+1][j] == 'G' && a[i+2][j] == 'W')
		{
			if(j>1 && j < m && a[i+1][j-1] == 'R' && a[i+1][j+1] == 'W') 
				link(pp(i,j), p(i+1,j-1));
			if(j>2 && a[i+2][j-2] == 'R' && a[i+2][j-1] == 'G') 
				link(pp(i,j), p(i+2,j-2));
			if(j <= m-2 && a[i][j+1] == 'G' && a[i][j+2] == 'W') 
				link(pp(i,j), p(i,j));
		}
	}
	int ans = 0;
	memset(seen,false,sizeof(seen));
	fo(i,1,n) fo(j,1,m) if(a[i][j] == 'R') 
	{
		if(j+2 <= m && a[i][j+1] == 'G' && a[i][j+2] == 'W')
		{
			int x = p(i,j);
			if(!seen[x])
			{
				s0 = s1 = 0; 
				assert(color(x));
				ans += max(s0, s1);
			}
		}
		if(i+2 <= n && a[i+1][j] == 'G' && a[i+2][j] == 'W')
		{
			int x = pp(i,j);
			if(!seen[x])
			{
				s0 = s1 = 0; 
				assert(color(x));
				ans += max(s0, s1);
			}
		}
	}
	pf("%d\n",ans);
	return 0;
}

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:60:4: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  sf("%d%d",&n,&m);
    ^
dango_maker.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fo(i,1,n) sf("%s",a[i]+1);
              ^
# Verdict Execution time Memory Grader output
1 Correct 49 ms 48376 KB Output is correct
2 Correct 50 ms 48376 KB Output is correct
3 Correct 48 ms 48376 KB Output is correct
4 Correct 45 ms 48376 KB Output is correct
5 Correct 46 ms 48404 KB Output is correct
6 Correct 46 ms 48348 KB Output is correct
7 Correct 47 ms 48348 KB Output is correct
8 Correct 47 ms 48376 KB Output is correct
9 Correct 48 ms 48380 KB Output is correct
10 Correct 48 ms 48384 KB Output is correct
11 Correct 49 ms 48380 KB Output is correct
12 Correct 48 ms 48348 KB Output is correct
13 Correct 48 ms 48376 KB Output is correct
14 Correct 48 ms 48376 KB Output is correct
15 Correct 52 ms 48504 KB Output is correct
16 Correct 54 ms 48332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 48376 KB Output is correct
2 Correct 50 ms 48376 KB Output is correct
3 Correct 48 ms 48376 KB Output is correct
4 Correct 45 ms 48376 KB Output is correct
5 Correct 46 ms 48404 KB Output is correct
6 Correct 46 ms 48348 KB Output is correct
7 Correct 47 ms 48348 KB Output is correct
8 Correct 47 ms 48376 KB Output is correct
9 Correct 48 ms 48380 KB Output is correct
10 Correct 48 ms 48384 KB Output is correct
11 Correct 49 ms 48380 KB Output is correct
12 Correct 48 ms 48348 KB Output is correct
13 Correct 48 ms 48376 KB Output is correct
14 Correct 48 ms 48376 KB Output is correct
15 Correct 52 ms 48504 KB Output is correct
16 Correct 54 ms 48332 KB Output is correct
17 Correct 47 ms 48472 KB Output is correct
18 Correct 55 ms 48356 KB Output is correct
19 Correct 48 ms 48376 KB Output is correct
20 Correct 50 ms 48428 KB Output is correct
21 Correct 58 ms 48504 KB Output is correct
22 Correct 51 ms 48376 KB Output is correct
23 Correct 54 ms 48348 KB Output is correct
24 Correct 48 ms 48348 KB Output is correct
25 Correct 47 ms 48348 KB Output is correct
26 Correct 55 ms 48384 KB Output is correct
27 Correct 48 ms 48380 KB Output is correct
28 Correct 48 ms 48384 KB Output is correct
29 Correct 49 ms 48376 KB Output is correct
30 Correct 49 ms 48376 KB Output is correct
31 Correct 48 ms 48376 KB Output is correct
32 Correct 48 ms 48376 KB Output is correct
33 Correct 46 ms 48376 KB Output is correct
34 Incorrect 53 ms 48376 KB Output isn't correct
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 48376 KB Output is correct
2 Correct 50 ms 48376 KB Output is correct
3 Correct 48 ms 48376 KB Output is correct
4 Correct 45 ms 48376 KB Output is correct
5 Correct 46 ms 48404 KB Output is correct
6 Correct 46 ms 48348 KB Output is correct
7 Correct 47 ms 48348 KB Output is correct
8 Correct 47 ms 48376 KB Output is correct
9 Correct 48 ms 48380 KB Output is correct
10 Correct 48 ms 48384 KB Output is correct
11 Correct 49 ms 48380 KB Output is correct
12 Correct 48 ms 48348 KB Output is correct
13 Correct 48 ms 48376 KB Output is correct
14 Correct 48 ms 48376 KB Output is correct
15 Correct 52 ms 48504 KB Output is correct
16 Correct 54 ms 48332 KB Output is correct
17 Correct 47 ms 48472 KB Output is correct
18 Correct 55 ms 48356 KB Output is correct
19 Correct 48 ms 48376 KB Output is correct
20 Correct 50 ms 48428 KB Output is correct
21 Correct 58 ms 48504 KB Output is correct
22 Correct 51 ms 48376 KB Output is correct
23 Correct 54 ms 48348 KB Output is correct
24 Correct 48 ms 48348 KB Output is correct
25 Correct 47 ms 48348 KB Output is correct
26 Correct 55 ms 48384 KB Output is correct
27 Correct 48 ms 48380 KB Output is correct
28 Correct 48 ms 48384 KB Output is correct
29 Correct 49 ms 48376 KB Output is correct
30 Correct 49 ms 48376 KB Output is correct
31 Correct 48 ms 48376 KB Output is correct
32 Correct 48 ms 48376 KB Output is correct
33 Correct 46 ms 48376 KB Output is correct
34 Incorrect 53 ms 48376 KB Output isn't correct
35 Halted 0 ms 0 KB -