QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#647718 | #5141. Identical Parity | comp_towels_cat | WA | 11ms | 3804kb | C++17 | 4.3kb | 2024-10-17 15:25:09 | 2024-10-17 15:25:09 |
Judging History
answer
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define FOR(i, j, k) for(int i = (j);i <= (k);i ++)
#define ROF(i, j, k) for(int i = (j);i >= (k);i --)
#define For(i, j, k) for(int i = (j);i < (k);i ++)
#define Rof(i, j, k) for(int i = (j);i > (k);i --)
#define ull unsigned long long
#define int long long
#define PII pair<int,int>
#define ULL unsigned long long
#define db double
#define x first
#define y second
#define sp(x) fixed << setprecision(x)
#define all(x) x.begin(), x.end()
#define unq_all(x) x.erase(unique(all(x)), x.end())
#define M(x) x %= mod, x += mod, x %= mod
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define ANS cout << ans << '\n'
#define de(p) cout << #p << ' ' << p << '\n'
#define END(i, n) (i == n ? '\n' : ' ')
#define double long double
#define RED cout << "\033[91m"
#define GREEN cout << "\033[92m"
#define YELLOW cout << "\033[93m"
#define BLUE cout << "\033[94m"
#define MAGENTA cout << "\033[95m"
#define CYAN cout << "\033[96m"
#define RESET cout << "\033[0m"
// 红色
#define DEBUG1(x) \
RED; \
cout << #x << " : " << x << endl; \
RESET;
// 绿色
#define DEBUG2(x) \
GREEN; \
cout << #x << " : " << x << endl; \
RESET;
// 蓝色
#define DEBUG3(x) \
BLUE; \
cout << #x << " : " << x << endl; \
RESET;
// 品红
#define DEBUG4(x) \
MAGENTA; \
cout << #x << " : " << x << endl; \
RESET;
// 青色
#define DEBUG5(x) \
CYAN; \
cout << #x << " : " << x << endl; \
RESET;
// 黄色
#define DEBUG6(x) \
YELLOW; \
cout << #x << " : " << x << endl; \
RESET;
using namespace std;
const int N = 5e5 + 10, M = 1e5 + 10, INF = 1e9, mod = 998244353;
int n, m, k;
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;
}
int gcd(int a, int b)
{
return b ? gcd(b,a % b) : a;
}
int lcm(int a, int b)
{
return a * b / gcd(a,b);
}
void solve()
{
cin >> n >> k;
// int odd = (n + 1) / 2;
// int even = n / 2;
if (n % k == 0)
{
if ((n / 2) % (n / k) == 0) YES;
else NO;
}
else
{
int c1 = n % k,v1 = n / k + 1;
int c2 = k - n % k,v2 = n / k;
int x,y;
int d = exgcd(v1,v2,x,y);
m = n / 2;
if (m % d == 0)
{
//x * v1 + y * v2 = m
int detx = v2 / d;
int dety = -v1 / d;
int t = m / d;
x *= t,y *= t;
// cout << x << ' ' << v1 <<' ' << y << ' ' << v2 << ' ' << m << '\n';
if (x < 0)
{
int T = (-x + detx - 1) / detx;
x += detx * T;
y += dety * T;
}
else
{
int T = x / detx;
x -= detx * T;
y -= dety * T;
}
// DEBUG6(c1)
// DEBUG6(c2)
// DEBUG6(detx)
// DEBUG6(dety)
// cout << x << ' ' << v1 <<' ' << y << ' ' << v2 << ' ' << m << '\n';
if (y > c2)
{
detx *= -1,dety *= -1;
int T = (y - c2 + dety - 1) / dety;
y -= dety * T;
x -= detx * T;
// cout << x << ' ' << v1 <<' ' << y << ' ' << v2 << ' ' << m << '\n';
if (x >= 0 && x <= c1) YES;
else NO;
}
else if (y < 0) NO;
else YES;
}
else
{
NO;
}
}
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
auto t = clock();
int T = 1;
cin >> T;
while (T--)
{
solve();
}
auto tt = clock();
// cout << "Time: " << 1000.0 * (tt - t) / CLOCKS_PER_SEC << "ms" << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3716kb
input:
3 3 1 4 2 5 3
output:
NO YES YES
result:
ok 3 token(s): yes count is 2, no count is 1
Test #2:
score: -100
Wrong Answer
time: 11ms
memory: 3804kb
input:
100000 1 1 2 1 2 2 3 1 3 2 3 3 4 1 4 2 4 3 4 4 5 1 5 2 5 3 5 4 5 5 6 1 6 2 6 3 6 4 6 5 6 6 7 1 7 2 7 3 7 4 7 5 7 6 7 7 8 1 8 2 8 3 8 4 8 5 8 6 8 7 8 8 9 1 9 2 9 3 9 4 9 5 9 6 9 7 9 8 9 9 10 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 11 1 11 2 11 3 11 4 11 5 11 6 11 7 11 8 11 9 11 10 11 11 12 1 ...
output:
YES NO YES NO YES YES NO YES YES YES NO YES YES YES YES NO YES NO YES YES YES NO YES YES YES YES YES YES NO YES YES YES YES YES YES YES NO YES NO YES YES YES YES YES YES NO YES NO YES NO YES YES YES YES YES NO YES NO YES YES YES YES YES YES YES YES NO YES NO YES YES YES YES YES YES YES YES YES NO YE...
result:
wrong answer expected NO, found YES [31st token]