QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#73205#2944. Transporting Spaghettiqdd#AC ✓3ms3536kbC++201.0kb2023-01-23 04:53:292023-01-23 04:53:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-23 04:53:30]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3536kb
  • [2023-01-23 04:53:29]
  • 提交

answer

// qdd on Jan 22, 2023

#ifdef qdd
#include <ringo>
#else
#include <bits/stdc++.h>
#define dbg(...)
#define dbgr(x, y)
#endif

using namespace std;

using ll = long long;

#define ALL(x) begin(x), end(x)

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  bool f = 0;
  for (const T& x : v) (f ? os << ' ' : os) << x, f = 1;
  return os;
}

void output(int x, int y) {
  if (x == -1) {
    cout << "No solution.\n";
  } else {
    cout << "We need " << x << (x == 1 ? " truck" : " trucks");
    cout << " and " << y << (y == 1 ? " boat.\n" : " boats.\n");
  }
}

void sol() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  for (int x = 0; x <= 10000; x++) {
    if ((c + d + x) % a == 0 && (c + x) % b == 0) {
      output((c + d + x) / a, (c + x) / b);
      return;
    }
  }
  output(-1, -1);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  sol();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3416kb

input:

100 20 30 10

output:

No solution.

result:

ok single line: 'No solution.'

Test #3:

score: 0
Accepted
time: 3ms
memory: 3416kb

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: 3384kb

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: 3308kb

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: 3376kb

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: 3536kb

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: 3416kb

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: 3372kb

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: 3464kb

input:

1 1 97 100

output:

We need 197 trucks and 97 boats.

result:

ok single line: 'We need 197 trucks and 97 boats.'