QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#723875 | #2944. Transporting Spaghetti | BackToSquare1 | AC ✓ | 0ms | 3680kb | C++20 | 1.2kb | 2024-11-08 02:09:15 | 2024-11-08 02:09:16 |
Judging History
answer
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef pair<ld,ld> pd;
typedef vector<ll> vl;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define G(x) ll x; cin >> x;
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define all(a) begin(a), end(a)
#define K first
#define V second
#define OK(i,j) i >= 0 && i < n && j >= 0 && j < m
#define NN 2505
#define MM 5005
#define MOD 1000007
void solve() {
ll A, B, C, D;
cin >> A >> B >> C >> D;
if(D%gcd(A,B) != 0) {
cout << "No solution.\n";
return;
}
ll t = 0;
while(t*A < D) t++;
while((t*A-D)%B != 0) t++;
ll b = (t*A - D)/B;
ll L = lcm(A,B);
while(t*A - D < C) {
t += L/A;
b += L/B;
}
cout << "We need " << t << " truck" << (t != 1 ? "s" : "") << " and " << b << " boat" << (b != 1 ? "s" : "") << ".\n";
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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: 3576kb
input:
100 20 30 10
output:
No solution.
result:
ok single line: 'No solution.'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3612kb
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: 3680kb
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: 3548kb
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: 0ms
memory: 3548kb
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: 0ms
memory: 3560kb
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: 0ms
memory: 3632kb
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: 0ms
memory: 3572kb
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: 0ms
memory: 3552kb
input:
1 1 97 100
output:
We need 197 trucks and 97 boats.
result:
ok single line: 'We need 197 trucks and 97 boats.'