QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629115#2944. Transporting SpaghettiTenshi#WA 0ms3828kbC++231.3kb2024-10-11 04:46:052024-10-11 04:46:05

Judging History

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

  • [2024-10-11 04:46:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3828kb
  • [2024-10-11 04:46:05]
  • 提交

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
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;
}

int exgcd(int a, int b, int &x, int &y){
	if(!b) return x=1, y=0, a;
	int d=exgcd(b, a%b, y, x);
	y-=a/b*x;
	return d;
}

int floor(int a, int b){
	if(a%b==0) return a/b;
	return ((a<0) xor (b<0)? a/b-1: a/b);
}

int ceil(int a, int b){
	return (a+b-1)/b;
}

void print(int x, int y){
	string fir="truck";
	string sec="boat";
	if(x>1) fir+="s";
	if(y>1) sec+="s";
	// We need 3 trucks and 5 boats.
	cout<<"We need "<<x<<" "<<fir<<" and "<<y<<" "<<sec<<".";
}

signed main(){
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	int x, y;
	int g=exgcd(a, b, x, y);
	// debug(x), debug(y);
	if(d%g){
		puts("No solution.");
		return 0;
	}
	
	x*=d/g, y*=d/g;
	int k=ceil(b*y+c, b*a/g);
	x+=k*b/g;
	y-=k*a/g;
	y=-y;
	print(x, y);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

31 13 50 28

output:

We need 3 trucks and 5 boats.

result:

ok single line: 'We need 3 trucks and 5 boats.'

Test #2:

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

input:

100 20 30 10

output:

No solution.

result:

ok single line: 'No solution.'

Test #3:

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

input:

1 1 1 100

output:

We need 101 trucks and 1 boat.

result:

ok single line: 'We need 101 trucks and 1 boat.'

Test #4:

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

input:

20 5 5 15

output:

We need 1 truck and 1 boat.

result:

ok single line: 'We need 1 truck and 1 boat.'

Test #5:

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

input:

100 20 100 100

output:

We need 2 trucks and 5 boats.

result:

ok single line: 'We need 2 trucks and 5 boats.'

Test #6:

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

input:

1 1 0 0

output:

We need 0 truck and 0 boat.

result:

wrong answer 1st lines differ - expected: 'We need 0 trucks and 0 boats.', found: 'We need 0 truck and 0 boat.'