QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#629121 | #2944. Transporting Spaghetti | Tenshi# | AC ✓ | 2ms | 3836kb | C++23 | 1.3kb | 2024-10-11 05:06:16 | 2024-10-11 05:06:16 |
Judging History
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), 1000000){
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3480kb
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: 2ms
memory: 3512kb
input:
100 20 30 10
output:
No solution.
result:
ok single line: 'No solution.'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3544kb
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: 2ms
memory: 3836kb
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: 2ms
memory: 3756kb
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: 0
Accepted
time: 2ms
memory: 3532kb
input:
1 1 0 0
output:
We need 0 trucks and 0 boats.
result:
ok single line: 'We need 0 trucks and 0 boats.'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3792kb
input:
1 5 10 50
output:
We need 60 trucks and 2 boats.
result:
ok single line: 'We need 60 trucks and 2 boats.'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3540kb
input:
100 1 100 100
output:
We need 2 trucks and 100 boats.
result:
ok single line: 'We need 2 trucks and 100 boats.'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3476kb
input:
1 1 100 100
output:
We need 200 trucks and 100 boats.
result:
ok single line: 'We need 200 trucks and 100 boats.'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3536kb
input:
1 1 97 100
output:
We need 197 trucks and 97 boats.
result:
ok single line: 'We need 197 trucks and 97 boats.'