QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#174941 | #5460. Sum of Numbers | realIyxiang# | WA | 39ms | 3704kb | C++14 | 2.4kb | 2023-09-10 14:48:51 | 2023-09-10 14:48:52 |
Judging History
answer
#include <bits/stdc++.h>
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)
using namespace std;
using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;
template < typename T > T read() {
T x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)) f |= ch == '-', ch = getchar();
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }
const int N = 1e6 + 10;
int n, K;
string num;
const bool operator < (const string &x, const string &y) {
if(x.size() != y.size()) return x.size() < y.size();
rep(i, (int)x.size() - 1, 0)
if(x[i] != y[i]) return x[i] < y[i];
return 1;
}
string getp(int l, int r) {
string ret; l--, r--;
rep(i, l, r) ret += num[i];
return ret;
}
string operator * (string a, string b) {
string t(max(a.size(), b.size()) + 1, 0);
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
rep(i, 0, max(a.size(), b.size())) {
if(i < a.size()) t[i] += a[i] - '0';
if(i < b.size()) t[i] += b[i] - '0';
if(t[i] >= 10) t[i + 1] += t[i] / 10, t[i] %= 10;
} while(t.back() == 0) t.pop_back(); for(auto &v : t) v += '0';
reverse(t.begin(), t.end());
/*cerr << "CALC: " << a << " " << b << " " << t << endl;*/ return t;
}
string get(vec pot) {
int cur = 1; string ret;
for(auto v : pot) {
int l = cur, r = l + v - 1;
//cerr << l << " " << r << " " << getp(l, r) << endl;
ret = ret * getp(l, r);
cur += v;
}// cerr << "!" << ret << endl;
return ret;
}
void solve() {
cin >> n >> K >> num;
int len = n / (K + 1);
string ans; bool fl = 0;
rep(s, 0, (1 << K + 1) - 1) if(__builtin_popcount(s) + len * (K + 1) == n) {
vec pot(K + 1, len); rep(j, 0, K) if(s >> j & 1) pot[j]++;
if(!fl) fl = 1, ans = get(pot);
else chkmin(ans, get(pot));
} cout << ans << endl;
}
int main() {
#ifdef YJR_2333_TEST
freopen("1.in", "r", stdin);
#endif
ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T; cin >> T;
for(; T; T--) solve(); return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 39ms
memory: 3704kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255 2028602090143780469266128133078232131914493056881109246886996709763987748451038085499863940159856016004397963081...
result:
wrong answer 2nd lines differ - expected: '133089789665597477403558640654...7219813869366061308627573151461', found: '202860209014378046926612813307...6715909234924381168614973744779'