QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751354 | #9738. Make It Divisible | yeVegeTable | WA | 0ms | 3784kb | C++20 | 3.0kb | 2024-11-15 18:16:47 | 2024-11-15 18:16:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef pair<ll, ll> P;
#define x first
#define y second
#define int long long
const int mod = 1e9 + 7;
const int pp = 998244353;
const int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}, dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const int ddx[8] = {1, 1, 2, 2, -1, -1, -2, -2}, ddy[8] = {2, -2, 1, -1, 2, -2, 1, -1};
ll ksm(ll a, ll b, ll p) {
ll ans = 1;
a %= p;
while(b) {
if(b & 1) ans = (ans * a) % p;
b >>= 1;
a = (a * a) % p;
}
return ans % p;
}
std::mt19937 rng; // 随机数生成器
int rand(int l, int r) {
std::uniform_int_distribution<int> distribution(l, r);
return distribution(rng);
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n + 2);
int idx = -1;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(i > 1 && a[i] != a[i - 1]) {
idx = i;
}
}
if(n == 1 || idx == -1) {
cout << k << " " << k * (k + 1) / 2 << endl;
return ;
}
vector<int> s(1);
vector<int> L(n + 1, -1);
for(int i = 1; i <= n; i++) {
while(s.size() && a[s.back()] <= a[i]) {
s.pop_back();
}
if(s.size()) {
L[i] = s.back();
}
s.emplace_back(i);
}
s = vector<int>(1, n + 1);
vector<int> R(n + 1, -1);
for(int i = n; i > 0; i--) {
while(s.size() && a[s.back()] <= a[i]) {
s.pop_back();
}
if(s.size()) {
R[i] = s.back();
}
s.emplace_back(i);
}
assert(R[1] != -1);
int A = a[1], B = a[R[1]], C = B - A;
// (B + x) = k * (A + x) -> B = k*A + (k-1)*x -> B - A = (A + x) * (k - 1)
set<int> st;
for(int i = 1; i * i <= C; i++) {
if(C % i) continue;
int f1 = i, f2 = C / i;
for(auto & j : {f1, f2}) {
if(j > A && j - A <= k) {
st.emplace(j - A);
}
}
}
int m = st.size();
vector<int> v;
for(auto & x : st) {
v.emplace_back(x);
}
vector<int> vis(m);
for(int i = 1; i <= n; i++) {
for(auto & j : {L[i], R[i]}) {
if(j == -1) continue;
for(int u = 0; u < m; u++) {
if(vis[u]) continue;
if((a[j] + v[u]) % (a[i] + v[u])) {
vis[u] = 1;
}
}
}
}
int cnt = 0, sum = 0;
for(int i = 0; i < m; i++) {
if(vis[i]) continue;
cnt ++ ;
sum += v[i];
}
cout << cnt << " " << sum << endl;
}
/*
*/
signed main () {
// init(minp, primes, m); // primes
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
// init();
int _ = 1;
cin >> _;
while(_ -- ) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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: 3784kb
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:
1 1 1 1 1 1 1 1
result:
wrong answer 1st lines differ - expected: '0 0', found: '1 1'