結果
| 問題 | No.3559 +A,-B |
| コンテスト | |
| ユーザー |
テナガザル
|
| 提出日時 | 2026-07-06 03:00:08 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,504 bytes |
| 記録 | |
| コンパイル時間 | 966 ms |
| コンパイル使用メモリ | 166,704 KB |
| 実行使用メモリ | 9,280 KB |
| 最終ジャッジ日時 | 2026-07-06 03:00:29 |
| 合計ジャッジ時間 | 7,752 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点1 | 10 % | WA * 4 |
| 部分点2 | 60 % | WA * 7 |
| 部分点3 | 30 % | WA * 20 |
| 合計 | 0 点 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void solve()
{
long long n, x, y, a, b;
cin >> n >> x >> y >> a >> b;
long long s = x + y;
if (s < 0 && s + a * (n - 1) < 0)
{
cout << x + a * n - y << ' ' << y << '\n';
return;
}
if (s >= 0 && s - b * (n - 1) >= 0)
{
cout << x << ' ' << y - b * n << '\n';
return;
}
if (a > b)
{
int l = 0, r = n;
while (r - l > 1)
{
long long mid = (l + r) / 2;
long long tx = x + mid * a, ty = y - (n - mid) * b;
long long ts = tx + ty;
if (ts < -b) l = mid;
else r = mid;
}
x += r * a;
y -= (n - r) * b;
cout << x << ' ' << y << '\n';
}
else if (a < b)
{
int l = 0, r = n;
while (r - l > 1)
{
long long mid = (l + r) / 2;
long long tx = x + mid * a, ty = y - (n - mid) * b;
long long ts = tx + ty;
if (ts >= a) r = mid;
else l = mid;
}
x += l * a;
y -= (n - l) * b;
cout << x << ' ' << y << '\n';
}
else
{
if (s < 0)
{
long long cnt = min(n, (-s + a - 1) / a);
n -= cnt;
x += cnt * a;
}
else
{
long long cnt = min(n, (s + b) / b);
n -= cnt;
y -= cnt * b;
}
if (x + y < 0)
{
x += (n + 1) / 2 * a;
y -= n / 2 * b;
}
else
{
x += n / 2 * a;
y -= (n + 1) / 2 * b;
}
cout << x << ' ' << y << '\n';
}
}
int main()
{
int t;
cin >> t;
while (t--) solve();
}
テナガザル