QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#756861 | #5141. Identical Parity | PHarr | WA | 0ms | 3616kb | C++23 | 1.3kb | 2024-11-16 22:19:43 | 2024-11-16 22:19:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i32 = int32_t;
using i64 = long long;
#define int i64
using vi = vector<int>;
using pii = pair<int, int>;
int exgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
int d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
void solve() {
int n, k;
cin >> n >> k;
if(k % 2 == 0) {
cout << "Yes\n";
return ;
}
int m = (n + 1) / 2;
int a = (n + k - 1) / k, b = n / k;
int p = n % k, q = k - p; // p is max x, q is max y
int x, y;
int d = exgcd(a, b, x, y);
if (m % d != 0) {
cout << "No\n";
return;
}
x = x * m / d, y = y * m / d;
cout << x << " " << y << "\n";
int dx = b / d, dy = a / d;
while(x >= dx) x -= dx, y += dy;
while(x < 0) x += dx, y -= dy;
while (x <= q) {
if(x + y > k) continue;
if (0 <= y and y <= q) {
cout << "Yes\n";
return;
}
x += dx, y -= dy;
}
cout << "No\n";
return;
}
i32 main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
cin >> T;
while (T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
3 3 1 4 2 5 3
output:
No Yes 0 3 Yes
result:
wrong output format YES or NO expected, but 0 found [3rd token]