QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#629119#2944. Transporting SpaghettiTenshi#WA 1ms3760kbC++231.3kb2024-10-11 05:03:222024-10-11 05:03:23

Judging History

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

  • [2024-10-11 05:03:23]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3760kb
  • [2024-10-11 05:03:22]
  • 提交

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=1e9, Y;
	rep(y, ceil(c, b), 100000){
		int t=b*y+d;
		if(t%a==0){
			int x=t/a;
			if(X>x) X=x, Y=y;
		}
	}
	if(X>1e8){
		puts("No solution.");
		return 0;
	}
	print(X, Y);
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3760kb

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: 1ms
memory: 3572kb

input:

100 20 30 10

output:

No solution.

result:

ok single line: 'No solution.'

Test #3:

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

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: 1ms
memory: 3636kb

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: 1ms
memory: 3552kb

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: 1ms
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.'