QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#375693#6823. Coffee OverdoseJCY_WA 12ms3700kbC++141.4kb2024-04-03 14:56:452024-04-03 14:56:47

Judging History

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

  • [2024-04-08 20:49:53]
  • hack成功,自动添加数据
  • (/hack/589)
  • [2024-04-03 14:56:47]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:3700kb
  • [2024-04-03 14:56:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i128 = __int128;
using u128 = unsigned __int128;
template <typename T>
void chkmax(T &x, const T &y) {
  if (x < y) x = y;
}
template <typename T>
void chkmin(T &x, const T &y) {
  if (y < x) x = y;
}
ll ceil_div(ll x, ll y) {
  assert(y);
  if (y < 0) {
    x = -x;
    y = -y;
  }
  return x >= 0 ? x / y : (x + 1) / y - 1;
}
constexpr ll INFLL = 0x3f3f3f3f3f3f3f3f;
ll get_max(ll a, ll b, ll c, ll l, ll r) {
  if (l > r) return -INFLL;
  ll x = min(max(ceil_div(-b, a * 2), l), r);
  ll ret = a * x * x + b * x + c;
  if (x != r) chkmin(ret, a * (x + 1) * (x + 1) + b * (x + 1) + c);
  return ret;
}
ll calc(int s, int c) {
  int k = s / (c + 1);
  ll ret = get_max(-1, c * 2 - k * 2 - 1, ((ll)c * c - 1) * k - (c + 1ll) * k * k, 0, s % (c + 1));
  chkmax(ret, get_max(-c, (ll)c * c - c * 2, (ll)c * c - c, 0, min(c, k) - 1));
  chkmax(ret, get_max(-c - 1, (ll)c * c - 1, 0, min(c, k), k - 1));
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int cas;
  cin >> cas;
  while (cas--) {
    int s, c;
    cin >> s >> c;
    cout << (ll)s * (s + 1) / 2 + calc(s, c) / 2 << "\n";
  }
  return 0;
}
/*
g++ C.cpp -o C -std=c++14 -O2 -Wall -Wextra -Wshadow -g -fsanitize=address,undefined
*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3700kb

input:

4
1 2
2 1
10 4
172800 172800

output:

2
3
63
29859840000

result:

ok 4 tokens

Test #2:

score: -100
Wrong Answer
time: 12ms
memory: 3684kb

input:

100000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 ...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

wrong answer 2502nd words differ - expected: '22', found: '21'