QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#175124 | #5460. Sum of Numbers | realIyxiang# | WA | 352ms | 4324kb | C++14 | 3.4kb | 2023-09-10 16:15:34 | 2023-09-10 16:15:35 |
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 < ll >;
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;
constexpr ll B = 1e16;
int n, K;
string num;
vec tnum;
const bool operator < (const vec &x, const vec &y) {
//cerr << "!COMP: " << x << " " << y << endl;
if(x.size() != y.size()) return x.size() < y.size();
per(i, (int)x.size() - 1, 0)
if(x[i] != y[i]) return x[i] < y[i];
return 1;
}
void compose(vec &x) {
vec ret;
rep(i, 0, (int)x.size() - 1) {
if(i % 16) ret.back() = ret.back() * 10 + x[i];
else ret.eb( x[i]);
} x = ret; reverse(x.begin(), x.end());
}
void depose(vec &x) {
reverse(x.begin(), x.end());
vec ret;
rep(i, 0, (int)x.size() - 1) {
rep(j, 0, 15) ret.eb( x[i] % 10 ), x[i] /= 10;
} while(ret.size() && ret.back() == 0) ret.pop_back(); x = ret;
}
vec getp(int l, int r) {
vec ret; l--, r--;
rep(i, l, r) ret.eb(tnum[i]);
compose(ret);
//cout << l << " " << r << " " << ret[0] << endl;
return ret;
}
vec operator * (const vec &a, const vec &b) {
vec t(max(a.size(), b.size()) + 1, 0);
rep(i, 0, max(a.size(), b.size())) {
if(i < a.size()) t[i] += a[i];
if(i < b.size()) t[i] += b[i];
if(t[i] >= B) t[i + 1] += t[i] / B, t[i] %= B;
} while(t.back() == 0) t.pop_back();
/*cerr << "CALC: " << a << " " << b << " " << t << endl;*/ return t;
}
vec get(const vec &pot) {
int cur = 1; vec ret;
//for(auto v : pot) cerr << v << " "; cerr << endl;
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;
//reverse(num.begin(), num.end());
vec().swap(tnum);
for(auto &v : num) v -= '0', tnum.eb(v);
int len = n / (K + 1);
vec ans; bool fl = 0;
auto upd = [&](const vec &ret) {
if(!fl) ans = ret, fl = 1;
else chkmin(ans, ret);
};
function < bool(int, int, vec) > dfs = [&](int cur, int tot, vec pot) {
if(tot > n) return 0;
if(cur == K + 1 && tot == n) return 0;
if(cur == K + 1 && n - tot > len + 1) return 0;
if(n - tot > (len + 1) * (K + 2 - cur)) return 0;
if(cur == K + 1) return pot.eb(n - tot), upd(get(pot)), 1;
int ptl = 0;
per(j, len + 1, 1) {
pot.eb(j);
bool tl = dfs(cur + 1, tot + j, pot);
pot.pop_back();
if(!tl) { if(j < len) break; } else ptl = 1;
} return ptl;
};
dfs(1, 0, {}); depose(ans);
//cerr << ct << endl;
reverse(ans.begin(), ans.end());
for(auto v : ans) cout << v; cout << 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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3448kb
input:
2 8 1 45455151 2 1 42
output:
9696 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 352ms
memory: 4324kb
input:
10 1301 6 56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...
output:
44679901255138085718676916740978624493356285159660961835192219032294648185346250672724491508148400147491179094757580459506363357533275680308876839611661970477729061939854636733938342862280000000000000003 274669378941520195864852172627960148467171500339279131163231787772359604108319838105999858539132...
result:
wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '446799012551380857186769167409...6733938342862280000000000000003'