Submission #69949062


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T,H,W;
string S[1010];
map<array<int,4>,int> memo;

int dfs(int L,int R,int U,int D,int t) {
	if(L==R&&U==D) {
		return S[U][L]==t+'0';
	}
	if(memo.count({L,R,U,D})) return memo[{L,R,U,D}];
	int win=0;
	if(L<R) {
		if(dfs(L+1,R,U,D,t^1)==0) win=1;
		if(dfs(L,R-1,U,D,t^1)==0) win=1;
	}
	if(U<D) {
		if(dfs(L,R,U+1,D,t^1)==0) win=1;
		if(dfs(L,R,U,D-1,t^1)==0) win=1;
	}
	return memo[{L,R,U,D}]=win;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>T;
	while(T--) {
		cin>>H>>W;
		FOR(y,H) cin>>S[y];
		int L=0,R=W-1;
		int U=0,D=H-1;
		while(R-L>=8) L++,R--;
		while(D-U>=8) U++,D--;
		memo.clear();
		
		if(dfs(L,R,U,D,1)) {
			cout<<"First"<<endl;
		}
		else {
			cout<<"Second"<<endl;
		}
		
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task D - Devourers and Cake
User kmjp
Language C++ 20 (gcc 12.2)
Score 800
Code Size 1581 Byte
Status AC
Exec Time 1209 ms
Memory 4764 KiB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:39:13: warning: unused variable ‘i’ [-Wunused-variable]
   39 |         int i,j,k,l,r,x,y; string s;
      |             ^
Main.cpp:39:15: warning: unused variable ‘j’ [-Wunused-variable]
   39 |         int i,j,k,l,r,x,y; string s;
      |               ^
Main.cpp:39:17: warning: unused variable ‘k’ [-Wunused-variable]
   39 |         int i,j,k,l,r,x,y; string s;
      |                 ^
Main.cpp:39:19: warning: unused variable ‘l’ [-Wunused-variable]
   39 |         int i,j,k,l,r,x,y; string s;
      |                   ^
Main.cpp:39:21: warning: unused variable ‘r’ [-Wunused-variable]
   39 |         int i,j,k,l,r,x,y; string s;
      |                     ^
Main.cpp:39:23: warning: unused variable ‘x’ [-Wunused-variable]
   39 |         int i,j,k,l,r,x,y; string s;
      |                       ^
Main.cpp: In function ‘int main(int, char**)’:
Main.cpp:6:19: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
Main.cpp:65:9: note: in expansion of macro ‘FOR’
   65 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |         ^~~
Main.cpp:6:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
Main.cpp:65:45: note: in expansion of macro ‘FOR’
   65 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                             ^~~
Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
Main.cpp:65:45: note: in expansion of macro ‘FOR’
   65 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                             ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 1
AC × 25
Set Name Test Cases
Sample sample_01.txt
All killer_01.txt, killer_02.txt, large_01.txt, large_02.txt, large_03.txt, large_04.txt, large_05.txt, max_01.txt, max_02.txt, max_03.txt, max_04.txt, medium_01.txt, medium_02.txt, medium_03.txt, medium_04.txt, medium_05.txt, sample_01.txt, small_01.txt, small_02.txt, small_03.txt, small_random_01.txt, small_random_02.txt, small_random_03.txt, small_random_04.txt, small_random_05.txt
Case Name Status Exec Time Memory
killer_01.txt AC 6 ms 3748 KiB
killer_02.txt AC 6 ms 3660 KiB
large_01.txt AC 3 ms 3832 KiB
large_02.txt AC 3 ms 3868 KiB
large_03.txt AC 3 ms 3756 KiB
large_04.txt AC 3 ms 3864 KiB
large_05.txt AC 3 ms 3848 KiB
max_01.txt AC 2 ms 4632 KiB
max_02.txt AC 2 ms 4764 KiB
max_03.txt AC 2 ms 4668 KiB
max_04.txt AC 2 ms 4576 KiB
medium_01.txt AC 58 ms 3552 KiB
medium_02.txt AC 61 ms 3584 KiB
medium_03.txt AC 55 ms 3568 KiB
medium_04.txt AC 58 ms 3584 KiB
medium_05.txt AC 59 ms 3584 KiB
sample_01.txt AC 1 ms 3452 KiB
small_01.txt AC 58 ms 3436 KiB
small_02.txt AC 399 ms 3512 KiB
small_03.txt AC 403 ms 3444 KiB
small_random_01.txt AC 1176 ms 3564 KiB
small_random_02.txt AC 1176 ms 3508 KiB
small_random_03.txt AC 1181 ms 3436 KiB
small_random_04.txt AC 1183 ms 3516 KiB
small_random_05.txt AC 1209 ms 3432 KiB