QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#348437 | #8169. R-Connected Components | ucup-team173# | WA | 0ms | 3648kb | C++20 | 3.3kb | 2024-03-09 18:28:59 | 2024-03-09 18:29:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define Mp make_pair
#define SZ(x) (int((x).size()))
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
void ssolve() {
for(int i = 1; i <= 5000; i++) {
vector<pii> ve;
for(int x = 0; x * x <= i; x++) {
int y = round(sqrt(i - x * x));
if(x * x + y * y == i) ve.pb(Mp(x, y));
}
if(SZ(ve) == 0) continue;
pii M = ve[0];
if(ve[0].fi == 0 || ve[0].se == 0) {
M.fi = M.se = ve[0].fi + ve[0].se;
} else {
M.fi = M.fi * 2, M.se = M.se * 2;
}
auto norm = [&](int &a, int b) {
if(b == 0) a = 0;
else a = ((a % b) + b) % b;
};
auto add = [&](pii a, pii b) {
a.fi += b.fi, a.se += b.se;
norm(a.fi, M.fi), norm(a.se, M.se);
return a;
};
vi fa((M.fi + 1) * (M.se + 1));
iota(fa.begin(), fa.end(), 0);
function<int(int)> find = [&](int x) {
return fa[x] == x ? x : fa[x] = find(fa[x]);
};
auto merge = [&](int x, int y) {
x = find(x), y = find(y);
if(x > y) swap(x, y);
fa[y] = x;
};
for(auto [x, y] : ve) {
for(int i = 0; i < M.fi; i++) {
for(int j = 0; j < M.se; j++) {
auto [ti, tj] = add(Mp(i, j), Mp(x, y));
merge(i * (M.se) + j, ti * (M.se) + tj);
}
}
}
int cnt = 0; vi ans;
for(int i = 0; i < (M.fi) * (M.se); i++)
if(find(i) == i) cnt++, ans.pb(i);
int yg = 0;
set<int> st;
for(auto [x, y] : ve) {
// cout << "(" << x << ',' << y << ") ";
st.insert(x&-x), st.insert(y&-y);
yg = __gcd(yg, y);
}
// cout << ' ';
int eig = cnt / yg / yg;
if(eig == 2) {
assert(SZ(st) == 1);
cout << i << ' ';
for(auto [x, y] : ve) {
cout << "(" << x << ',' << y << ") ";
}
cout << '\n';
} else {
assert(SZ(st) != 1);
}
// cout << i << ' ' << eig << '\n';
// cout << '\n';
int xmx = 0, ymx = 0;
for(auto i : ans) {
xmx = max(xmx, i / M.se);
ymx = max(ymx, i % M.se);
// cout << i / (M.se) << ' ' << i % (M.se) << " | ";
}
// cout << '\n' << xmx + 1 << ' ' << ymx + 1 << ' ' << yg;
assert(cnt == (xmx + 1) * (ymx + 1));
// cout << "\n";
}
}
void solve() {
int R;
cin >> R;
set<int> st;
int g = 0, fl = 0;
for(int i = 0; i * i <= R; i++) {
int j = round(R - i * i);
if(i * i + j * j != R) continue;
fl = 1;
st.insert(i & -i);
st.insert(j & -j);
g = __gcd(g, i);
g = __gcd(g, j);
}
if(fl == 0) {
cout << "inf\n";
} else if(SZ(st) == 1) {
cout << 2ll * g * g << '\n';
} else {
cout << 1ll * g * g << '\n';
}
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int t = 1;
cin >> t;
while(t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
3 1 2 3
output:
1 2 inf
result:
ok 3 tokens
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3648kb
input:
100 971962039 377418539 436722941 974460973 408831757 674955527 838941797 566099869 224191573 85539073 544795513 157335071 243499759 907206901 570172403 871918511 594778897 773009569 9371917 23810669 169348601 804358351 78636461 382633897 182514781 846151963 274168729 929192339 91532527 172531889 18...
output:
inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf inf ...
result:
wrong answer 3rd words differ - expected: '1', found: 'inf'