QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142399 | #5460. Sum of Numbers | ElDiablo# | RE | 1ms | 3580kb | C++14 | 2.5kb | 2023-08-19 01:41:49 | 2023-08-19 01:41:52 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#include <queue>
#include <numeric>
#include <cstring>
#define f(x, a, b) for (int x = a; x < b; x++)
#define fm(x, a, b) for (int x = a; x > b; x--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
using namespace std;
typedef unsigned long long ll;
typedef long long int li;
const li mod=1e9+7;
const int val = 100;
struct bignum {
int dig[val];
bignum() {
memset(dig,0,sizeof(dig));
}
bignum(string &s, int l, int r) {
memset(dig,0,sizeof(dig));
int j=0;
fm(i,r-1,l-1) {
dig[j]=s[i]-'0';
j++;
}
}
void add(bignum &b) {
int carry=0;
f(i,0,val) {
dig[i]+=b.dig[i]+carry;
carry=dig[i]/10;
dig[i]%=10;
}
}
bool greater(bignum &b) {
fm(i,val-1,-1) {
if (dig[i]>b.dig[i])
return true;
if (dig[i]<b.dig[i])
return false;
}
return false;
}
void print() {
int i=val-1;
while (i>=0 && dig[i]==0)
i--;
if (i==-1)
cout <<0;
else {
fm(j,i,-1)
cout <<dig[j];
}
cout <<"\n";
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >>t;
while(t--) {
int n,k;
cin >>n>>k;
k++;
string s;
cin >>s;
int d1 = n/k;
int ex = n%k;
string x;
f(i,0,n)
x+='9';
bignum cmax(x,0,n);
f(i,0,1<<k) {
if (__builtin_popcount(i)==ex) {
int i1 = 0;
bignum csum;
f(j,0,k) {
if (i&(1<<j)) {
bignum c(s,i1,i1+d1+1);
csum.add(c);
i1+=d1+1;
}
else {
bignum c(s,i1,i1+d1);
csum.add(c);
i1+=d1;
}
}
if (!csum.greater(cmax))
swap(csum,cmax);
}
}
cmax.print();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Runtime Error
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...