QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602478#5259. Skills in PillsxymWA 2ms11536kbC++201.3kb2024-10-01 02:03:132024-10-01 02:03:15

Judging History

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

  • [2024-10-01 02:03:15]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11536kb
  • [2024-10-01 02:03:13]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define endl "\n"
#define ll long long
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using namespace std;
const int N = 1e6+7,p = 998244353;

int T;
int n,k,j;
int dp[N][2];//0-BA    1-AB
int d0,d1;
int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}
void solve(){
	cin>>k>>j>>n;
	int lcm = j*k/gcd(j,k);
	for(int i=1;i<=n;i++){
		if(!d0&&i%k==0&&(i+1)%j==0){
			d0 = i;
		}
		if(!d1&&i%j==0&&(i+1)%k==0){
			d1 = i;
		}
	}
	if(!d0) d0 = n+1;
	if(!d1) d1 = n+1;
	memset(dp,inf,sizeof dp);
	dp[lcm][0] = dp[lcm][1] = lcm/k+lcm/j;
	int ad0 = d0/k+(d0+1)/j,ad1 = d1/j+(d1+1)/k;
	int ans = inf;
	for(int i=1;i<=n;i++){
		if(dp[i][0]==inf){
			dp[i][0] = min((i-d0>0&&dp[i-d0][0]!=inf) ? dp[i-d0][0]+ad0:inf,
			(i-d1>0&&dp[i-d1][1]!=inf) ? dp[i-d1][1]+ad1:inf);
			dp[i][1] = min((i-d0>0&&dp[i-d0][0]!=inf) ? dp[i-d0][0]+ad0:inf,
			(i-d1>0&&dp[i-d1][1]!=inf) ? dp[i-d1][1]+ad1:inf);
		}
		if(i+d0>n){
			ans = min(ans,dp[i][0]+(n-i)/k+(n-i+1)/j);
		}
		if(i+d1>n){
			ans = min(ans,dp[i][1]+(n-i+1)/k+(n-i)/j);
		}
	}
	cout<<ans;
}
signed main(){
	IOS;
//	cin>>T;
	T = 1;
	while(T--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 9 20

output:

8

result:

ok single line: '8'

Test #2:

score: 0
Accepted
time: 2ms
memory: 11432kb

input:

8 2 12

output:

7

result:

ok single line: '7'

Test #3:

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

input:

2 5 15

output:

10

result:

ok single line: '10'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 11400kb

input:

10 8 13

output:

1061109567

result:

wrong answer 1st lines differ - expected: '2', found: '1061109567'