Submission #70048843


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 N,M;
ll A[66];
ll ret;
unordered_map<ll,ll> memo0,memo1;

void dfs1(ll sum,int pre,int id) {
	if(id==N/2) {
		memo0[sum]++;
		if(pre==0) memo1[sum]++;
		return;
	}
	dfs1(sum,0,id+1);
	if(pre==0) dfs1((sum+A[id])%M,1,id+1);
}
void dfs2(ll sum,int pre,int id) {
	if(id==N/2-1) {
		if(pre==0) {
			ret+=memo0[(M-sum)%M];
		}
		else {
			ret+=memo1[(M-sum)%M];
		}
		return;
	}
	dfs2(sum,0,id-1);
	if(pre==0) dfs2((sum+A[id])%M,1,id-1);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,N) {
		cin>>A[i];
	}
	
	dfs1(0,0,0);
	dfs2(0,0,N-1);
	
	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 F - Not Adjacent
User kmjp
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1446 Byte
Status AC
Exec Time 2380 ms
Memory 250772 KiB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:45:15: warning: unused variable ‘j’ [-Wunused-variable]
   45 |         int i,j,k,l,r,x,y; string s;
      |               ^
Main.cpp:45:17: warning: unused variable ‘k’ [-Wunused-variable]
   45 |         int i,j,k,l,r,x,y; string s;
      |                 ^
Main.cpp:45:19: warning: unused variable ‘l’ [-Wunused-variable]
   45 |         int i,j,k,l,r,x,y; string s;
      |                   ^
Main.cpp:45:21: warning: unused variable ‘r’ [-Wunused-variable]
   45 |         int i,j,k,l,r,x,y; string s;
      |                     ^
Main.cpp:45:23: warning: unused variable ‘x’ [-Wunused-variable]
   45 |         int i,j,k,l,r,x,y; string s;
      |                       ^
Main.cpp:45:25: warning: unused variable ‘y’ [-Wunused-variable]
   45 |         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:62:9: note: in expansion of macro ‘FOR’
   62 |         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:62:45: note: in expansion of macro ‘FOR’
   62 |         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:62:45: note: in expansion of macro ‘FOR’
   62 |         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 525 / 525
Status
AC × 3
AC × 53
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3440 KiB
00_sample_01.txt AC 1 ms 3464 KiB
00_sample_02.txt AC 1 ms 3452 KiB
01_random_03.txt AC 2311 ms 250196 KiB
01_random_04.txt AC 2380 ms 250172 KiB
01_random_05.txt AC 2341 ms 250528 KiB
01_random_06.txt AC 2250 ms 249244 KiB
01_random_07.txt AC 2280 ms 250416 KiB
01_random_08.txt AC 2144 ms 246392 KiB
01_random_09.txt AC 2268 ms 250696 KiB
01_random_10.txt AC 2292 ms 250440 KiB
01_random_11.txt AC 1 ms 3504 KiB
01_random_12.txt AC 4 ms 4436 KiB
01_random_13.txt AC 1 ms 3700 KiB
01_random_14.txt AC 48 ms 17424 KiB
01_random_15.txt AC 7 ms 5504 KiB
01_random_16.txt AC 2189 ms 244188 KiB
01_random_17.txt AC 2284 ms 250212 KiB
01_random_18.txt AC 2275 ms 250444 KiB
01_random_19.txt AC 2213 ms 250772 KiB
01_random_20.txt AC 114 ms 12916 KiB
01_random_21.txt AC 2128 ms 246020 KiB
01_random_22.txt AC 2170 ms 250072 KiB
01_random_23.txt AC 1448 ms 178756 KiB
01_random_24.txt AC 1 ms 3648 KiB
01_random_25.txt AC 2 ms 4148 KiB
01_random_26.txt AC 3 ms 4364 KiB
01_random_27.txt AC 1 ms 3484 KiB
01_random_28.txt AC 9 ms 6688 KiB
01_random_29.txt AC 891 ms 123876 KiB
01_random_30.txt AC 1474 ms 178700 KiB
01_random_31.txt AC 975 ms 127632 KiB
01_random_32.txt AC 755 ms 96220 KiB
01_random_33.txt AC 1137 ms 139052 KiB
01_random_34.txt AC 1046 ms 124532 KiB
01_random_35.txt AC 1527 ms 178348 KiB
01_random_36.txt AC 1003 ms 127860 KiB
01_random_37.txt AC 1 ms 3496 KiB
01_random_38.txt AC 1 ms 3604 KiB
01_random_39.txt AC 1 ms 3504 KiB
01_random_40.txt AC 1 ms 3600 KiB
01_random_41.txt AC 17 ms 8080 KiB
01_random_42.txt AC 47 ms 3632 KiB
01_random_43.txt AC 47 ms 3500 KiB
01_random_44.txt AC 52 ms 3412 KiB
01_random_45.txt AC 47 ms 3524 KiB
01_random_46.txt AC 46 ms 3508 KiB
01_random_47.txt AC 70 ms 3404 KiB
01_random_48.txt AC 47 ms 3512 KiB
01_random_49.txt AC 1 ms 3400 KiB
01_random_50.txt AC 1 ms 3436 KiB
01_random_51.txt AC 1 ms 3432 KiB
01_random_52.txt AC 1 ms 3512 KiB