結果
| 問題 | No.3559 +A,-B |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-25 20:30:37 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 226 ms / 2,000 ms |
| コード長 | 2,275 bytes |
| 記録 | |
| コンパイル時間 | 2,448 ms |
| コンパイル使用メモリ | 335,576 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-29 18:56:05 |
| 合計ジャッジ時間 | 9,736 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_1 |
| 純コード判定待ち |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点1 | 10 % | AC * 4 |
| 部分点2 | 60 % | AC * 7 |
| 部分点3 | 30 % | AC * 20 |
| 合計 | 100 点 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
#define all(a) begin(a), end(a)
#define sz(a) ssize(a)
template<class T, class U> bool chmin(T& a, U b) { return a > b ? a = b, 1 : 0; }
template<class T, class U> bool chmax(T& a, U b) { return a < b ? a = b, 1 : 0; }
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using lll = __int128_t;
istream &operator>>(istream &is, lll& v) {
string s; cin >> s;
v = 0;
for(char c:s){if(isdigit(c))v=v*10+(c-'0');}
if(s[0]=='-') v*=-1;
return is;
}
ostream &operator<<(ostream &os, lll v) {
if(!ostream::sentry(os)) return os;
char buf[64];
char *d=end(buf);
lll tmp = (v<0?-v:v);
do{d--;*d=char(tmp%10+'0');tmp/=10;}while(tmp);
if(v<0) {d--;*d = '-';}
int len=end(buf)-d;
if(os.rdbuf()->sputn(d, len)!=len){os.setstate(ios_base::badbit);}
return os;
}
#define _O(_1, _2, _3, n, ...) n
#define _r1(i, n) for(ll i = 0; i < (ll)(n); i++)
#define _r2(i, l, r) for(ll i = (ll)(l); i < (ll)(r); i++)
#define rep(...) _O(__VA_ARGS__, _r2, _r1)(__VA_ARGS__)
#define _rr1(i, n) for(ll i = (ll)(n) - 1; i >= 0; i--)
#define _rr2(i, l, r) for(ll i = (ll)(r) - 1; i >= (ll)(l); i--)
#define rrep(...) _O(__VA_ARGS__, _rr2, _rr1)(__VA_ARGS__)
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
ll i = 0;
for(auto& x : v) o << (i++ ? " " : "") << x;
return o;
}
template<class H, class... T> void out(const H& h, const T&... t) {
cout << h;
((cout << " " << t), ...);
cout << endl;
}
int main(){
ll _; cin >> _;
while(_--){
lll n,x,y,a,b; cin >> n >> x >> y >> a >> b;
if(x+y < 0 && x+y+n*a < 0) {
out(x+a*n,y);
continue;
}
if(x+y >= 0 && x+y-n*b >= 0) {
out(x,y-b*n);
continue;
}
if(x+y >= 0){
lll k = (x+y)/b+1;
n -= k;
y -= b*k;
}else{
lll k = (-(x+y+1))/a+1;
n -= k;
x += a*k;
}
if(x+y < 0 && x+y+n*a < 0) {
out(x+a*n,y);
continue;
}
if(x+y >= 0 && x+y-n*b >= 0) {
out(x,y-b*n);
continue;
}
lll z = (x+y+a*n) % (a+b);
if(z >= a) z -= a+b;
if(z < -b) z += a+b;
out((b*x-a*y+a*b*n+a*z)/(a+b),(a*y-b*x-a*b*n+b*z)/(a+b));
}
}