QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#513064 | #9167. Coprime Array | ucup-team1264# | WA | 501ms | 3828kb | C++20 | 2.5kb | 2024-08-10 16:47:08 | 2024-08-10 16:47:11 |
Judging History
answer
// https://www.youtube.com/watch?v=wthasN45KuY
// You said I’d fly away
// But my walls have kept me down
// Now I’m lost and I’m afraid
// And I’m close to hit the ground
//
// You said I’d fly away
// You said I’d fly anywhere
// But I keep on Falling
#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
#define int i64
void solve() {
int s, x; cin >> s >> x;
if (gcd(s, x) == 1) {
cout << 1 << "\n";
cout << s << "\n";
}
// Goldbach's conjecture
if (x <= 20000) {
vector<int> dp(x + 1, 1e9 + 7), fa(x + 1, -1);
dp[0] = 0;
vector<int> cop_nums;
dp[1] = 1; cop_nums.push_back(1); fa[1] = 1;
for (int i = 2; i <= x; i++) {
if (gcd(i, x) == 1) {
dp[i] = 1;
cop_nums.push_back(i);
fa[i] = i;
continue;
}
for (int cop: cop_nums) {
if (dp[i - cop] + 1 < dp[i]) {
dp[i] = dp[i - cop] + 1;
fa[i] = cop;
}
}
}
debug(dp);
cout << dp[s % x] << "\n";
vector<int> ans;
while (s % x != 0) {
ans.push_back(fa[s % x]);
s -= fa[s % x];
}
ans[0] += s;
for (int x: ans) cout << x << " ";
cout << "\n";
} else {
auto time = chrono::high_resolution_clock::now();
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using chrono_literals::operator""ms;
while (chrono::high_resolution_clock::now() - time < 500ms) {
int t = rng() % (x - 1) + 1;
if (gcd(t, x) == 1 && gcd(s - t, x) == 1) {
cout << 2 << "\n";
cout << t << " " << s - t << "\n";
return;
}
}
while (true) {
int t1 = rng() % (x - 1) + 1, t2 = rng() % (x - 1) + 1;
if (gcd(t1, x) == 1 && gcd(t2, x) == 1 && gcd(s - t1 - t2, x) == 1) {
cout << 3 << "\n";
cout << t1 << " " << t2 << " " << s - t1 - t2 << "\n";
return;
}
}
}
}
#undef int
// Make bold hypotheses and verify carefully
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3488kb
input:
9 6
output:
3 7 1 1
result:
ok Correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
14 34
output:
2 1 13
result:
ok Correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
1000000000 223092870
output:
2 21306587 978693413
result:
ok Correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
2 1000000000
output:
2 681123249 -681123247
result:
ok Correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
649557664 933437700
output:
2 289554857 360002807
result:
ok Correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
33396678 777360870
output:
2 35948567 -2551889
result:
ok Correct
Test #7:
score: 0
Accepted
time: 500ms
memory: 3608kb
input:
48205845 903124530
output:
3 396000019 472941619 -820735793
result:
ok Correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
251037078 505905400
output:
2 46577997 204459081
result:
ok Correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
30022920 172746860
output:
2 24570217 5452703
result:
ok Correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
63639298 808058790
output:
2 622587641 -558948343
result:
ok Correct
Test #11:
score: 0
Accepted
time: 501ms
memory: 3608kb
input:
76579017 362768406
output:
3 255690979 139478413 -318590375
result:
ok Correct
Test #12:
score: 0
Accepted
time: 500ms
memory: 3596kb
input:
40423669 121437778
output:
3 81794553 30981817 -72352701
result:
ok Correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
449277309 720915195
output:
2 317074061 132203248
result:
ok Correct
Test #14:
score: 0
Accepted
time: 500ms
memory: 3608kb
input:
81665969 919836918
output:
3 243623063 655860857 -817817951
result:
ok Correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
470578680 280387800
output:
2 144660149 325918531
result:
ok Correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
58450340 803305503
output:
2 343409104 -284958764
result:
ok Correct
Test #17:
score: 0
Accepted
time: 496ms
memory: 3600kb
input:
125896113 323676210
output:
3 41213243 204148169 -119465299
result:
ok Correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
381905348 434752500
output:
2 196921807 184983541
result:
ok Correct
Test #19:
score: -100
Wrong Answer
time: 0ms
memory: 3524kb
input:
78916498 653897673
output:
1 78916498 2 17369015 61547483
result:
wrong output format Extra information in the output file