Submission #17170104


Source Code Expand

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
ll mo;

ll from[5050*100+100];
ll to[5050*100+100];
ll ret[101];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>mo;
	
	
	for(x=1;x<=(N+1)/2;x++) {
		ZERO(from);
		ZERO(to);
		int mi=x*(x-1)/2*K;
		int ma=(N-x)*(N-x+1)/2*K;
		int cur=mi+50;
		from[cur]=K+1;
		mi=ma=cur;
		for(i=x-1;i>=1;i--) {
			int pma=ma;
			
			mi=min(mi,mi+K*(i-x));
			ma=max(ma,ma+K*(i-x));
			ll sum[101]={};
			for(y=ma;y>=mi;y--) {
				to[y]=from[y];
				if(y+(x-i)<=pma) to[y]+=to[y+(x-i)];
				if(y-(K+1)*(i-x)<=pma) to[y]+=mo-from[y-(K+1)*(i-x)];
				while(to[y]>=mo) to[y]-=mo;
			}
			swap(from,to);
		}
		for(i=x+1;i<=N;i++) {
			int pmi=mi;
			for(y=mi;y<=cur;y++) {
				to[y]=from[y];
				if(y+(x-i)>=mi) to[y]+=to[y+(x-i)];
				if(y-(K+1)*(i-x)>=pmi) to[y]+=mo-from[y-(K+1)*(i-x)];
				while(to[y]>=mo) to[y]-=mo;
			}
			swap(from,to);
		}
		ret[x]=(from[cur]+mo-1)%mo;
		ret[(N+1)-x]=ret[x];
	}
	
	for(i=1;i<=N;i++) cout<<ret[i]<<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 - Multiset Mean
User kmjp
Language C++ (GCC 9.2.1)
Score 700
Code Size 1739 Byte
Status AC
Exec Time 2545 ms
Memory 11548 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:41:7: warning: unused variable ‘sum’ [-Wunused-variable]
   41 |    ll sum[101]={};
      |       ^~~
./Main.cpp:23:8: warning: unused variable ‘j’ [-Wunused-variable]
   23 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:23:10: warning: unused variable ‘k’ [-Wunused-variable]
   23 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:23:12: warning: unused variable ‘l’ [-Wunused-variable]
   23 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:23:14: warning: unused variable ‘r’ [-Wunused-variable]
   23 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:7:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    7 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:72:38: note: in expansion of macro ‘FOR’
   72 |  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 700 / 700
Status
AC × 3
AC × 23
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 13 ms 11476 KB
02.txt AC 53 ms 11444 KB
03.txt AC 131 ms 11344 KB
04.txt AC 320 ms 11400 KB
05.txt AC 433 ms 11340 KB
06.txt AC 739 ms 11460 KB
07.txt AC 862 ms 11388 KB
08.txt AC 1253 ms 11392 KB
09.txt AC 1908 ms 11496 KB
10.txt AC 2200 ms 11460 KB
11.txt AC 2265 ms 11460 KB
12.txt AC 2493 ms 11504 KB
13.txt AC 2106 ms 11400 KB
14.txt AC 2495 ms 11344 KB
15.txt AC 2545 ms 11504 KB
16.txt AC 13 ms 11440 KB
17.txt AC 1259 ms 11548 KB
18.txt AC 946 ms 11384 KB
19.txt AC 365 ms 11396 KB
20.txt AC 140 ms 11444 KB
s1.txt AC 14 ms 11504 KB
s2.txt AC 15 ms 11340 KB
s3.txt AC 32 ms 11388 KB