QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546381 | #1807. Distribute the Bars | surgutti | WA | 0ms | 3660kb | C++17 | 1016b | 2024-09-04 00:16:07 | 2024-09-04 00:16:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int p = 2;
while (p < n) {
if (n % p == 0)
break;
p++;
}
if (p == n) {
cout << "-1\n";
return 0;
}
if (n % 2 == 0) {
cout << n / 2 << '\n';
for (int i = 1; i <= n / 2; i++) {
cout << 2 << ' ' << 2 * i - 1 << ' ' << 2 * (n - i + 1) - 1 << '\n';
}
return 0;
}
vector<vector<int>> groups(p);
int i = 1;
while (i + p * p - 1 <= n) {
for (int j = 0; j < p; j++) {
for (int k = 0; k < p; k++) {
groups[(j + k) % p].push_back(2 * (i + j * p + k) - 1);
}
}
i += p * p;
}
int cur = 0;
for (int l = i, r = n; l < r; l++, r--) {
groups[cur].push_back(2 * l - 1);
groups[cur].push_back(2 * r - 1);
cur = (cur + 1) % p;
}
cout << groups.size() << '\n';
for (auto g : groups) {
cout << g.size() << ' ';
for (int x : g)
cout << x << ' ';
cout << '\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
4
output:
2 2 1 7 2 3 5
result:
ok OK (2 groups)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
2
output:
-1
result:
ok OK (impossible)
Test #3:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
3
output:
-1
result:
ok OK (impossible)
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3528kb
input:
1659
output:
3 554 1 11 15 19 29 33 37 47 51 55 65 69 73 83 87 91 101 105 109 119 123 127 137 141 145 155 159 163 173 177 181 191 195 199 209 213 217 227 231 235 245 249 253 263 267 271 281 285 289 299 303 307 317 321 325 335 339 343 353 357 361 371 375 379 389 393 397 407 411 415 425 429 433 443 447 451 461 465...
result:
wrong answer Not all bars are distributed