Submission #72909391
Source Code Expand
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
long long T, n, m, a, b;
long long solve(long long n, long long a, long long b, long long m, long long c)
{
if (n <= 0)
return 0;
if (a == 0)
{
if (c < 0)
return n;
else
return 0;
}
long long k0 = (m - b + a - 1) / a;
if (k0 > n - 1)
{
if (a == 1)
{
if (c < 0)
return n;
else
return 0;
}
long long kmax = (-c - 1) / (a - 1);
if (kmax < 0)
return 0;
long long r = min(n - 1, kmax);
return r + 1;
}
long long cnt1 = 0;
if (k0 > 0)
{
if (a == 1)
{
if (c < 0)
cnt1 = min(k0, n);
else
cnt1 = 0;
}
else
{
long long kmax = (-c - 1) / (a - 1);
if (kmax >= 0)
{
long long r = min(k0 - 1, min(n - 1, kmax));
if (r >= 0)
cnt1 = r + 1;
}
}
}
long long n2 = n - k0;
long long b2 = (a * k0 + b) - m;
long long c2 = b2 + c - b - k0;
return cnt1 + solve(n2, a, b2, m, c2);
}
int main()
{
cin >> T;
while (T--)
{
cin >> n >> m >> a >> b;
if (n == 0)
cout << 0 << endl;
if (a == 0)
cout << min(n, b) << endl;
if (a == 1)
{
if (b == 0)
cout << 0 << endl;
else
cout << min(n, m - b) << endl;
}
cout << n - solve(n, a, b, m, b - 1) << endl;
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | G - Another Mod of Linear Problem |
| User | xzy404 |
| Language | C++23 (GCC 15.2.0) |
| Score | 0 |
| Code Size | 1776 Byte |
| Status | WA |
| Exec Time | > 2000 ms |
| Memory | 6596 KiB |
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 575 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt |
| All | 00_sample_00.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | WA | 1 ms | 3596 KiB |
| 01_random_00.txt | TLE | > 2000 ms | 3380 KiB |
| 01_random_01.txt | TLE | > 2000 ms | 3292 KiB |
| 01_random_02.txt | TLE | > 2000 ms | 3364 KiB |
| 01_random_03.txt | TLE | > 2000 ms | 3304 KiB |
| 01_random_04.txt | TLE | > 2000 ms | 3248 KiB |
| 01_random_05.txt | TLE | > 2000 ms | 3212 KiB |
| 01_random_06.txt | TLE | > 2000 ms | 3332 KiB |
| 01_random_07.txt | TLE | > 2000 ms | 3292 KiB |
| 01_random_08.txt | TLE | > 2000 ms | 3328 KiB |
| 01_random_09.txt | TLE | > 2000 ms | 3288 KiB |
| 01_random_10.txt | WA | 81 ms | 3536 KiB |
| 01_random_11.txt | TLE | > 2000 ms | 3228 KiB |
| 01_random_12.txt | WA | 371 ms | 6596 KiB |
| 01_random_13.txt | WA | 393 ms | 3592 KiB |
| 01_random_14.txt | WA | 394 ms | 3476 KiB |
| 01_random_15.txt | WA | 244 ms | 3472 KiB |
| 01_random_16.txt | TLE | > 2000 ms | 3332 KiB |
| 01_random_17.txt | TLE | > 2000 ms | 3320 KiB |
| 01_random_18.txt | TLE | > 2000 ms | 3284 KiB |
| 01_random_19.txt | TLE | > 2000 ms | 3228 KiB |
| 01_random_20.txt | TLE | > 2000 ms | 3248 KiB |
| 01_random_21.txt | TLE | > 2000 ms | 3380 KiB |
| 01_random_22.txt | TLE | > 2000 ms | 3284 KiB |
| 01_random_23.txt | TLE | > 2000 ms | 3292 KiB |
| 01_random_24.txt | TLE | > 2000 ms | 3308 KiB |