QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866134#7304. Coins 2InvincibleWA 156ms9504kbC++232.0kb2025-01-22 12:47:122025-01-22 12:47:12

Judging History

你现在查看的是最新测评结果

  • [2025-01-22 12:47:12]
  • 评测
  • 测评结果:WA
  • 用时:156ms
  • 内存:9504kb
  • [2025-01-22 12:47:12]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <ctime>
#include <random>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int, int>
#define fi first
#define se second
#define MP make_pair
#define ep emplace
#define eb emplace_back
//#define int long long
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
typedef double db;
typedef long double ldb;
typedef long long ll;
//typedef __int128 lll;
typedef unsigned long long ull;
typedef unsigned int ui;
using namespace std;
using namespace __gnu_pbds;
bool Mbe;

//char buf[1<<20],*p1,*p2;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin), p1 == p2) ? 0 : *p1++)
int read() {
	int s = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
	return f ? s : -s;
}
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(x>y)x=y;}

int n,a[20],m;
ll sum,ans;
bool f[5765765];
void Knapsack(int lim){
	memset(f,0,lim+1);
	f[0]=1;
	rep(i,1,n)if(a[i]){
		rep(j,0,i-1){
			int lst=-1;
			for(int k=j;k<=lim;k+=i){
				if(f[k])lst=k;
				if(~lst&&(k-lst)/i<=a[i])f[k]=1;
			}
		}
	}
}

bool Med;
signed main() {
	fprintf(stderr,"%.3lfMb\n",(&Mbe-&Med)/1024./1024.);
	while(scanf("%d",&n)==1){
		m=1,sum=ans=0;
		rep(i,1,n)sum+=(ll)i*(a[i]=read());
		rep(i,1,n)m=m*i/__gcd(i,m);
		Knapsack(min((ll)(n+1)*m-1,sum));
		rep(i,0,n*m-1)ans+=f[i]*((i<=sum)+(sum-i>=n*m));
		int tmp=0;
		rep(i,n*m,(n+1)*m-1)tmp+=f[i];
		if(sum>=2*n*m){
			int dif=2*n*m-sum;
			ans+=(ll)dif/m*tmp;
			rep(i,1,dif%m)ans+=f[n*m+i-1];
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3968kb

input:

3
0 1 2
3
0 2 3

output:

6
12

result:

ok 2 number(s): "6 12"

Test #2:

score: -100
Wrong Answer
time: 156ms
memory: 9504kb

input:

1
0
15
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

output:

1
280705888

result:

wrong answer 2nd numbers differ - expected: '120000000001', found: '280705888'