QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#554103#2753. Picking Up the DiceTenshi#AC ✓106ms11708kbC++201.9kb2024-09-09 05:51:302024-09-09 05:51:30

Judging History

This is the latest submission verdict.

  • [2024-09-09 05:51:30]
  • Judged
  • Verdict: AC
  • Time: 106ms
  • Memory: 11708kb
  • [2024-09-09 05:51:30]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
 
#define x first
#define y second
#define int long long
using pii = pair<int, int>;
using ll = long long;
 
inline void read(int &x){
    int s=0; x=1;
    char ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();}
    while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    x*=s;
}

set<int> f[1010];
int n, T;
int w[1010];
int g[1010][1010];

bool gt(pii a, pii b){
	__int128 fir=(__int128)a.x*b.y;
	__int128 sec=(__int128)a.y*b.x;
	
	return fir>sec;
}

bool eq(pii a, pii b){
	__int128 fir=(__int128)a.x*b.y;
	__int128 sec=(__int128)a.y*b.x;
	return fir==sec;
}

signed main(){
	cin>>n>>T;
	rep(i, 1, n) read(w[i]);
	
	// memset(f, 0xcf, sizeof f);
	f[0].insert(0);
	rep(i, 1, n){
		dwn(j, 200, w[i]){
			if(f[j-w[i]].size()){
				for(auto e: f[j-w[i]]){
					f[j].insert(e+1);
				}
			}
		}
		// f[j]=max(f[j], f[j-w[i]]+1);
	}
	
	int res=n+10;
	pii p={0, 1};
	rep(s, 0, T){
		for(auto fs: f[s]){
			// debug(f[s]);
			int t=T-s;
			int r=n-fs;
			if(r<=n){
				// r 个,并且 roll 出 t 的方案数 x
				memset(g, 0, sizeof g);
				g[0][0]=1;
				rep(i, 1, r){
					rep(j, 1, 6){
						rep(k, j, t){
							g[i][k]+=g[i-1][k-j];
						}
					}
				}
				
				int x=g[r][t];
				int y=1;
				rep(i, 1, r) y*=6;
				// cerr<<r<<" "<<y<<endl;
				
				// if(r==12) debug(t);
				
				pii np={x, y};
				if(gt(np, p)){
					res=r;
					p=np;
				}
				else if(eq(np, p)){
					res=min(res, r);
				}
				
				// debug(t),debug(r);
				// cerr<<p.x<<" "<<p.y<<endl;
				// if(r==12) cerr<<p.x<<" "<<p.y<<endl;
				// if(r==12) cerr<<np.x<<" "<<np.y<<endl;
			}
		}
	}
	cout<<res;
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 11708kb

input:

2 7
3 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 29ms
memory: 11616kb

input:

10 46
1 2 3 4 5 6 1 2 3 4

output:

6

result:

ok single line: '6'

Test #3:

score: 0
Accepted
time: 102ms
memory: 11572kb

input:

20 96
1 2 3 4 5 6 1 2 3 4 1 2 3 4 5 6 1 2 3 4

output:

16

result:

ok single line: '16'

Test #4:

score: 0
Accepted
time: 6ms
memory: 11700kb

input:

24 144
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 9ms
memory: 11556kb

input:

24 24
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 3ms
memory: 11612kb

input:

24 72
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4

output:

24

result:

ok single line: '24'

Test #7:

score: 0
Accepted
time: 8ms
memory: 11708kb

input:

6 11
1 2 3 4 5 6

output:

3

result:

ok single line: '3'

Test #8:

score: 0
Accepted
time: 11ms
memory: 11556kb

input:

6 16
1 2 3 4 5 6

output:

1

result:

ok single line: '1'

Test #9:

score: 0
Accepted
time: 8ms
memory: 11640kb

input:

6 26
1 2 3 4 5 6

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 0ms
memory: 11616kb

input:

6 6
1 2 3 4 5 6

output:

5

result:

ok single line: '5'

Test #11:

score: 0
Accepted
time: 0ms
memory: 11624kb

input:

3 9
5 4 1

output:

1

result:

ok single line: '1'

Test #12:

score: 0
Accepted
time: 3ms
memory: 11552kb

input:

4 13
2 2 2 2

output:

3

result:

ok single line: '3'

Test #13:

score: 0
Accepted
time: 91ms
memory: 11660kb

input:

18 90
1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6

output:

12

result:

ok single line: '12'

Test #14:

score: 0
Accepted
time: 10ms
memory: 11576kb

input:

6 21
1 2 3 4 5 6

output:

0

result:

ok single line: '0'

Test #15:

score: 0
Accepted
time: 93ms
memory: 11636kb

input:

21 42
1 2 4 1 5 3 1 6 5 1 1 4 1 5 6 5 6 2 6 1 1

output:

10

result:

ok single line: '10'

Test #16:

score: 0
Accepted
time: 30ms
memory: 11624kb

input:

19 20
2 4 6 4 3 1 1 6 2 3 2 2 1 2 3 3 5 2 2

output:

16

result:

ok single line: '16'

Test #17:

score: 0
Accepted
time: 42ms
memory: 11636kb

input:

12 49
1 1 5 3 6 1 1 2 3 5 6 5

output:

4

result:

ok single line: '4'

Test #18:

score: 0
Accepted
time: 106ms
memory: 11628kb

input:

20 74
2 6 1 4 1 3 4 2 3 1 5 1 3 6 3 3 3 6 2 1

output:

5

result:

ok single line: '5'