QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#763177 | #7026. Let the Flames Begin | xucheng | TL | 0ms | 0kb | C++14 | 1016b | 2024-11-19 18:42:25 | 2024-11-19 18:42:25 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, m, k;
cin >> n >> m >> k;
int p = n - m + 1;
int ans = (k - 1) % p;
if (m < k) {
for (int i = 2; i <= m; i ++ ) {
ans = (ans + k) % (++ p);
}
} else {
int a = n - m + 1;
if (k == 1) {
cout << m << "\n";
return;
}
while (a < n) {
int x = (int)(ceil(1.0 * (a - ans)) / (k - 1));
if (a + x > n) {
x = n - a;
}
p = a + x;
ans = (ans + x * k) % p;
a = a + x;
}
}
cout << ans + 1 << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int TestCaseNumber = 1;
cin >> TestCaseNumber;
for (int i = 1; i <= TestCaseNumber; i ++ ) {
cout << "Case #" << i << ": ";
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
20 10 1 2 10 2 2 10 3 2 10 4 2 10 5 2 10 6 2 10 7 2 10 8 2 10 9 2 10 10 2 10 1 3 10 2 3 10 3 3 10 4 3 10 5 3 10 6 3 10 7 3 10 8 3 10 9 3 10 10 3