Submission #18273725


Source Code Expand

Copy
#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 N;
int C[2][2];
const ll mo=1000000007;

int ok(int v,int N) {
	if(N==2) return 1;
	for(int i=1;i<=N-2;i++) {
		int x=(v>>(i+1))&1;
		int y=(v>>(i-1))&1;
		int r=(v>>i)&1;
		
		if(C[x][y]==r) {
			int n=(v&((1<<i)-1)) | ((v>>(i+1))<<i);
			if(ok(n,N-1)) return 1;
		}
	}
	return 0;
	
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(y,2) FOR(x,2) {
		cin>>s;
		C[y][x]=s[0]-'A';
	}
	if(N<=3) return _P("1\n");
	
	
	int mask;
	int num=0;
	FOR(mask,1<<(7)) {
		int v=(mask<<1)|1;
		if(ok(v,9)) {
			num++;
		}
	}
	
	if(num==1) {
		cout<<1<<endl;
	}
	else if(num==21) {
		ll F[1010]={};
		F[1]=F[2]=1;
		for(i=3;i<=1005;i++) F[i]=(F[i-1]+F[i-2])%mo;
		cout<<F[N-1]<<endl;
	}
	else if(num==64) {
		ll ret=1;
		FOR(i,N-3) ret=ret*2%mo;
		cout<<ret<<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 - AB
User kmjp
Language C++ (GCC 9.2.1)
Score 600
Code Size 1660 Byte
Status AC
Exec Time 10 ms
Memory 3660 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:39:8: warning: unused variable ‘j’ [-Wunused-variable]
   39 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:39:10: warning: unused variable ‘k’ [-Wunused-variable]
   39 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:39:12: warning: unused variable ‘l’ [-Wunused-variable]
   39 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:39:14: warning: unused variable ‘r’ [-Wunused-variable]
   39 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp: In function ‘int main(int, char**)’:
./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:79:38: note: in expansion of macro ‘FOR’
   79 |  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 600 / 600
Status
AC × 2
AC × 82
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, hand_17.txt, hand_18.txt, hand_19.txt, hand_20.txt, hand_21.txt, hand_22.txt, hand_23.txt, hand_24.txt, hand_25.txt, hand_26.txt, hand_27.txt, hand_28.txt, hand_29.txt, hand_30.txt, hand_31.txt, hand_32.txt, hand_33.txt, hand_34.txt, hand_35.txt, hand_36.txt, hand_37.txt, hand_38.txt, hand_39.txt, hand_40.txt, hand_41.txt, hand_42.txt, hand_43.txt, hand_44.txt, hand_45.txt, hand_46.txt, hand_47.txt, hand_48.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand_01.txt AC 6 ms 3548 KB
hand_02.txt AC 2 ms 3576 KB
hand_03.txt AC 3 ms 3624 KB
hand_04.txt AC 2 ms 3620 KB
hand_05.txt AC 3 ms 3576 KB
hand_06.txt AC 3 ms 3564 KB
hand_07.txt AC 3 ms 3656 KB
hand_08.txt AC 3 ms 3508 KB
hand_09.txt AC 3 ms 3616 KB
hand_10.txt AC 2 ms 3508 KB
hand_11.txt AC 2 ms 3524 KB
hand_12.txt AC 4 ms 3504 KB
hand_13.txt AC 2 ms 3504 KB
hand_14.txt AC 2 ms 3620 KB
hand_15.txt AC 2 ms 3624 KB
hand_16.txt AC 2 ms 3616 KB
hand_17.txt AC 3 ms 3524 KB
hand_18.txt AC 3 ms 3520 KB
hand_19.txt AC 2 ms 3460 KB
hand_20.txt AC 2 ms 3620 KB
hand_21.txt AC 2 ms 3596 KB
hand_22.txt AC 3 ms 3648 KB
hand_23.txt AC 2 ms 3652 KB
hand_24.txt AC 2 ms 3508 KB
hand_25.txt AC 2 ms 3572 KB
hand_26.txt AC 2 ms 3620 KB
hand_27.txt AC 2 ms 3560 KB
hand_28.txt AC 4 ms 3460 KB
hand_29.txt AC 3 ms 3508 KB
hand_30.txt AC 3 ms 3544 KB
hand_31.txt AC 2 ms 3512 KB
hand_32.txt AC 3 ms 3508 KB
hand_33.txt AC 4 ms 3608 KB
hand_34.txt AC 2 ms 3516 KB
hand_35.txt AC 2 ms 3456 KB
hand_36.txt AC 4 ms 3572 KB
hand_37.txt AC 3 ms 3580 KB
hand_38.txt AC 2 ms 3568 KB
hand_39.txt AC 2 ms 3584 KB
hand_40.txt AC 3 ms 3572 KB
hand_41.txt AC 2 ms 3620 KB
hand_42.txt AC 3 ms 3616 KB
hand_43.txt AC 7 ms 3588 KB
hand_44.txt AC 3 ms 3604 KB
hand_45.txt AC 2 ms 3616 KB
hand_46.txt AC 2 ms 3620 KB
hand_47.txt AC 3 ms 3660 KB
hand_48.txt AC 5 ms 3500 KB
random_01.txt AC 4 ms 3516 KB
random_02.txt AC 2 ms 3456 KB
random_03.txt AC 2 ms 3572 KB
random_04.txt AC 4 ms 3608 KB
random_05.txt AC 3 ms 3568 KB
random_06.txt AC 3 ms 3460 KB
random_07.txt AC 2 ms 3568 KB
random_08.txt AC 3 ms 3616 KB
random_09.txt AC 3 ms 3500 KB
random_10.txt AC 3 ms 3460 KB
random_11.txt AC 3 ms 3456 KB
random_12.txt AC 10 ms 3504 KB
random_13.txt AC 3 ms 3508 KB
random_14.txt AC 4 ms 3500 KB
random_15.txt AC 2 ms 3584 KB
random_16.txt AC 2 ms 3572 KB
random_17.txt AC 2 ms 3460 KB
random_18.txt AC 3 ms 3612 KB
random_19.txt AC 2 ms 3516 KB
random_20.txt AC 3 ms 3512 KB
random_21.txt AC 2 ms 3608 KB
random_22.txt AC 2 ms 3580 KB
random_23.txt AC 2 ms 3620 KB
random_24.txt AC 4 ms 3520 KB
random_25.txt AC 3 ms 3560 KB
random_26.txt AC 4 ms 3644 KB
random_27.txt AC 4 ms 3568 KB
random_28.txt AC 4 ms 3612 KB
random_29.txt AC 3 ms 3580 KB
random_30.txt AC 3 ms 3552 KB
random_31.txt AC 2 ms 3568 KB
random_32.txt AC 3 ms 3656 KB
sample_01.txt AC 3 ms 3460 KB
sample_02.txt AC 4 ms 3560 KB