QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#878808 | #9738. Make It Divisible | PinkRabbit# | WA | 1ms | 3712kb | C++20 | 2.6kb | 2025-02-01 17:54:17 | 2025-02-01 17:54:18 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include <cmath>
using std::cin, std::cout;
#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define F2(i, a, b) for(int i = a; i < (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)
void Solve();
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
cin >> tests;
while (tests--)
Solve();
return 0;
}
using LL = long long;
const int Mod = 998244353;
const int Inf = 0x3f3f3f3f;
const LL InfLL = 0x3f3f3f3f3f3f3f3f;
const int MN = 500005;
int n, k;
int a[MN];
void Solve() {
cin >> n >> k;
F(i, 1, n) cin >> a[i];
n = (int)(std::unique(a + 1, a + n + 1) - a - 1);
if (n == 1)
return void(cout << k << ' ' << (LL)k * (k + 1) / 2 << '\n');
int d = std::abs(a[2] - a[1]);
std::vector<int> factors;
for (int i = 1; (LL)i * i <= d; ++i)
if (d % i == 0)
factors.push_back(i);
dF(i, (int)factors.size() - 1, 0)
factors.push_back(d / factors[i]);
factors.resize(std::unique(factors.begin(), factors.end()) - factors.begin());
int ansc = 0;
LL anss = 0;
for (int dd : factors) {
int x = dd - std::min(a[1], a[2]);
if (x <= 0)
continue;
bool ok = true;
F(i, 1, n - 1) {
int mx = std::max(a[i], a[i + 1]);
int mn = std::min(a[i], a[i + 1]);
if ((mx + x) % (mn + x) != 0) {
ok = false;
break;
}
}
if (!ok)
continue;
std::vector<int> b(a + 1, a + n + 1);
while ((int)b.size() >= 2) {
std::vector<int> tmp;
F2(i, 0, (int)b.size())
if ((i >= 1 && b[i - 1] < b[i]) || (i <= (int)b.size() - 2 && b[i + 1] < b[i]))
;
else
tmp.push_back(b[i]);
tmp.resize(std::unique(tmp.begin(), tmp.end()) - tmp.begin());
b.swap(tmp);
bool okk = true;
F(i, 0, (int)b.size() - 2) {
int mx = std::max(b[i], b[i + 1]);
int mn = std::min(b[i], b[i + 1]);
if ((mx + x) % (mn + x) != 0) {
okk = false;
break;
}
}
if (!okk) {
ok = false;
break;
}
}
if (!ok)
continue;
++ansc;
anss += x;
}
cout << ansc << ' ' << anss << '\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
3 5 10 7 79 1 7 1 2 1000000000 1 2 1 100 1000000000
output:
3 8 0 0 100 5050
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3712kb
input:
4 201 1000000000 1 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5 2 5...
output:
0 0 1 1 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0 0', found: '1 1'