QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356913 | #5456. Big Picture | ucup-team1001 | WA | 0ms | 3564kb | C++23 | 3.1kb | 2024-03-18 15:49:12 | 2024-03-18 15:49:13 |
Judging History
answer
/*
Author: Haze
2024/3/17
*/
#include <bits/stdc++.h>
#define irep(i, l, r) for(int i = (l); i <= (r); ++ i)
#define drep(i, r, l) for(int i = (r); i >= (l); -- i)
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr);
using namespace std;
typedef long long ll;
inline ll read() {
ll s = 0;
bool fl = false;
char ch = (char) getchar();
while (!isdigit(ch)) {
if (ch == '-')fl = true;
ch = (char) getchar();
}
while (isdigit(ch)) {
s = s * 10 + (ch ^ 48);
ch = (char) getchar();
}
return fl ? -s : s;
}
constexpr int P = 1E9;
struct BigInt {
std::vector<int> v;
};
void add(BigInt &a, const BigInt &b){
a.v.resize(std::max(a.v.size(), b.v.size()) + 1);
for (int i = 0; i < b.v.size(); i++) {
a.v[i] += b.v[i];
if(a.v[i] >= 10)a.v[i] -= 10, a.v[i + 1] ++;
}
while (a.v.back() == 0) {
a.v.pop_back();
}
}
bool operator<(const BigInt &a, const BigInt &b) {
if (a.v.size() != b.v.size()) {
return a.v.size() < b.v.size();
}
for (int i = int(a.v.size()) - 1; i >= 0; i--) {
if (a.v[i] != b.v[i]) {
return a.v[i] < b.v[i];
}
}
return false;
}
void print(const BigInt &a) {
const auto &v = a.v;
if (v.empty()) {
std::cout << "0\n";
return;
}
std::cout << v.back();
for (int i = int(v.size()) - 2; i >= 0; i--) {
cout << v[i];
}
std::cout << "\n";
}
const int mod = 1000000000 + 7;
const int itinf = 1000000999;
const ll llinf = 2e18;
const int N = 500099;
void solve() {
int n, k;
vector<int> del(20);
cin >> n >> k;
string s;
cin >> s;
++k;
reverse(s.begin(), s.end());
BigInt ANS;
bool fl = false;
function<void(int)> dfs = [&](int x) {
if (x == k) {
if ((n - accumulate(del.begin(), del.end(), 0)) % k == 0) {
vector<int> dig(k);
int D = (n - accumulate(del.begin(), del.end(), 0)) / k;
irep(i, 0, k - 1) {
dig[i] = D + del[i];
if (dig[i] == 0)return;
}
BigInt A;
int p = 0;
irep(i, 0, k - 1) {
BigInt B;
B.v.resize(dig[i]);
int tot = 0;
while (p < n && dig[i]) {
B.v[tot++] = s[p] - '0';
++p;
--dig[i];
}
add(A,B);
// if(fl && A.v.size() > ANS.v.size())return;
}
if (!fl)fl = true, ANS = A;
else if (A < ANS)ANS = A;
}
return;
}
del[x] = -1;
dfs(x + 1);
del[x] = 0;
dfs(x + 1);
del[x] = 1;
dfs(x + 1);
};
dfs(0);
print(ANS);
}
int main() {
IOS
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
3 3 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0 1 0 1
output:
-173-480 0 0
result:
wrong output format Expected integer, but "-173-480" found