QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789021 | #9738. Make It Divisible | shinonomezhou | WA | 0ms | 3604kb | C++14 | 2.0kb | 2024-11-27 19:04:59 | 2024-11-27 19:04:59 |
Judging History
answer
#include "bits/stdc++.h"
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define endl "\n"
#define double long double
const int N = 3e5 + 10;
const ll INF = 0x3f3f3f3f3f3f3f;
ll dengcha(ll kk) {
if (kk & 1)
return ((kk + 1) / 2) * kk;
return (kk / 2) * (kk + 1);
}
ll n, m, k;
void solve() {
cin >> n >> k;
vector<ll> b(n + 5), lm(n + 5), rm(n + 5);
set<ll> tp;
for (int i = 1; i <= n; i++) {
cin >> b[i];
tp.insert(b[i]);
}
if (tp.size() == 1) {
cout << k << ' ';
cout << fixed << setprecision(0) << dengcha(k) << endl;
return;
}
set<pll> st;
stack<pll> sta;
sta.push({0, 0});
for (int i = 1; i <= n; i++) {
while (b[i] <= sta.top().first) {
sta.pop();
}
lm[i] = sta.top().second;
sta.push({b[i], i});
}
while (!sta.empty())
sta.pop();
sta.push({0, n + 1});
for (int i = n; i >= 1; i--) {
while (b[i] <= sta.top().first) {
sta.pop();
}
rm[i] = sta.top().second;
sta.push({b[i], i});
}
for (int i = 1; i <= n; i++) {
if (lm[i] > 0)
st.insert({b[lm[i]], b[i]});
if (rm[i] <= n)
st.insert({b[rm[i]], b[i]});
}
ll mi = INF, x, y;
for (auto e : st) {
if (e.second - e.first < mi) {
mi = e.second - e.first;
x = e.first, y = e.second;
}
}
ll cnt = 0, ans = 0;
set<ll> anss;
for (ll i = 1; i * i <= y - x; i++) {
if ((y - x) / i - 1 >= 1)
anss.insert((y - x) / i - 1);
if (i - 1 >= 1)
anss.insert(i - 1);
}
for (auto e : anss) {
bool ff = true;
for (auto t : st) {
if ((t.second + e) % (t.first + e) != 0) {
ff = false;
break;
}
}
if (ff) {
cnt++;
ans += e;
}
}
cout << cnt << ' ';
cout << fixed << setprecision(0) << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int _ = 1;
cin >> _;
while (_--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: 0
Accepted
time: 0ms
memory: 3556kb
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 0 0 0 0 0 0
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3600kb
input:
500 4 1000000000 8 14 24 18 4 1000000000 17 10 18 14 4 1000000000 6 17 19 19 4 1000000000 15 14 15 25 4 1000000000 16 16 5 25 4 1000000000 4 30 20 5 4 1000000000 11 4 23 9 4 1000000000 14 25 13 2 4 1000000000 18 18 1 15 4 1000000000 22 22 22 28 4 1000000000 15 17 17 10 4 1000000000 22 14 13 25 4 100...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 178th lines differ - expected: '1 2', found: '0 0'