QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#394989#7111. Press the Buttonucup-team055#WA 3ms3536kbC++231.5kb2024-04-20 23:58:522024-04-20 23:58:54

Judging History

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

  • [2024-04-20 23:58:54]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3536kb
  • [2024-04-20 23:58:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
const ll INF = LLONG_MAX / 4;
#define rep(i, a, b) for(ll i = a; i < (b); i++)
#define sz(a) ssize(a)
bool chmin(auto& a, auto b) { if(a <= b) return 0; a = b; return 1; }
bool chmax(auto& a, auto b) { if(a >= b) return 0; a = b; return 1; }

using u128 = __uint128_t;
u128 floor_sum(u128 n, u128 m, u128 a, u128 b) {
   u128 ans = 0;
   while(1) {
      if(a >= m) {
         ans += n * (n - 1) / 2 * (a / m);
         a %= m;
      }
      if(b >= m) {
         ans += n * (b / m);
         b %= m;
      }
      u128 y_max = a * n + b;
      if(y_max < m) break;
      n = y_max / m;
      b = y_max % m;
      swap(m, a);
   }
   return ans;
}
ll solve() {
    ll a, b, c, d, v, t;
    cin >> a >> b >> c >> d >> v >> t;
    const ll A = t / a + 1, C = t / c + 1;
    if(min(a, c) <= v) return A * b + C * d - 1;
    ll ans = A * (b - 1) + C * (d - 1);
    // a の前 -v, …, -1 秒に c が押していれば +1
    const ll lastA = A * a, C_ = lastA / c + 1;
    ans += floor_sum(C_, a, c, v) - floor_sum(C_, a, c, 0);
    // c の前 -v, …, -1 秒に a が押していれば +1
    const ll lastC = C * c, A_ = lastC / a + 1;
    ans += floor_sum(A_, c, a, v) - floor_sum(A_, c, a, 0);
    // a と c 同時に押したら +1
    ans += t / lcm(a, c) + 1;
    return ans;
}
int main() {
    ll T;
    cin >> T;
    while(T--) cout << solve() << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
8 2 5 1 2 18
10 2 5 1 2 10

output:

6
4

result:

ok 2 number(s): "6 4"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3536kb

input:

1000
8 6 2 6 3 17
1 6 1 1 1 30
5 4 8 8 1 31
7 6 10 3 6 12
9 1 4 4 3 38
3 3 5 8 1 8
9 1 5 2 3 18
6 10 10 8 2 40
9 6 9 10 3 9
2 5 1 10 10 39
7 7 1 2 4 19
8 10 8 6 7 36
2 9 1 1 7 17
1 2 3 5 6 14
8 8 8 7 1 46
6 9 3 9 4 6
10 8 1 7 10 18
7 1 7 10 3 50
1 10 2 1 5 1
5 8 4 9 7 44
9 2 5 4 7 42
9 1 2 1 1 20
5 ...

output:

71
216
52
18
39
23
9
104
30
499
60
75
98
54
84
44
148
80
20
179
45
5
463
139
57
30
45
127
204
121
42
69
38
98
63
121
25
142
17
75
24
175
115
40
32
11
29
85
35
7
67
49
492
49
49
14
17
53
431
161
94
27
23
135
71
92
33
290
58
300
18
89
157
55
10
219
203
390
28
50
67
213
26
18
27
19
128
101
118
62
46
16...

result:

wrong answer 4th numbers differ - expected: '16', found: '18'