QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#89278#5259. Skills in PillsCCSU_LRFWA 2ms3528kbC++141.4kb2023-03-19 15:23:492023-03-19 15:23:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-19 15:23:52]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3528kb
  • [2023-03-19 15:23:49]
  • 提交

answer


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll lcm1,lcm2,lcm3;
ll lcm(ll a,ll b){
    return a/__gcd(a,b)*b;
}
struct node{
    int a,b,c;
};
ll n,m,k;
int check(ll b,ll c){
    if(lcm1 >= lcm2) c--;
    else b --;
    c = max(0ll,c);
    b = max(0ll,b);
    //return lcm1*b+lcm2*c+lcm(n,m)+min(lcm2,lcm1);
    if(lcm1*b+lcm2*c+lcm3+max(lcm2,lcm1) > k) return 1;
    else return 0;
}
int main()
{
    cin>>n>>m>>k;
    if(n==m) {
        cout<<k/m+(k+1)/n<<'\n';
        return 0;
    }
    lcm1 = lcm(n-1,m);
    lcm2 = lcm(n,m-1);
    lcm3 = lcm(n,m);
    ll ans = 0x3f3f3f3f;
    int ix ,ixx;
    for(int i = 0;i<=k;i++){
        ll l = 0,r =k;
        while(l<r){
            ll c = (l+r)>>1;
            if(check(i,c)) r = c;
            else l = c+1;
           // cout<<l<<" "<<r<<" "<<check(i,c)<<'\n';
        }
        //cout<<l<<'\n';
        if((i+k)/n+(l+k)/m < ans){
            ans = (i+k)/n+(l+k)/m;
            ix = i,ixx = l;
        }
    }
    ans = 0;
    int a = 0,b = 0;
    for(int i = 1;i<=k;i++){
    	a++,b++;
    	if(i==lcm3){
    		ans += 2;
    		a = b = 0;
    		if(lcm1>lcm2&&ixx) b++;  
		}
		else if(a%n==0&&b%m==0){
    		ans += 2;
    		a = b = 0;
    		if(ix) a++,ix--;
			else b++,ixx--; 
		}
		else if(a%n==0) {
			ans ++ ;
			a = 0;
		}
		else if(b%m==0){
			ans ++;
			b = 0;
		}
	}
	cout<<ans<<'\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 9 20

output:

8

result:

ok single line: '8'

Test #2:

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

input:

8 2 12

output:

7

result:

ok single line: '7'

Test #3:

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

input:

2 5 15

output:

10

result:

ok single line: '10'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3376kb

input:

10 8 13

output:

2

result:

ok single line: '2'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3340kb

input:

6 6 19

output:

6

result:

ok single line: '6'

Test #6:

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

input:

2 3 5

output:

3

result:

ok single line: '3'

Test #7:

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

input:

4 2 8

output:

6

result:

ok single line: '6'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3336kb

input:

5 5 5

output:

2

result:

ok single line: '2'

Test #9:

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

input:

3 8 11

output:

4

result:

ok single line: '4'

Test #10:

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

input:

5 8 16

output:

5

result:

ok single line: '5'

Test #11:

score: -100
Wrong Answer
time: 2ms
memory: 3340kb

input:

9 7 279

output:

71

result:

wrong answer 1st lines differ - expected: '70', found: '71'