QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#174963#5460. Sum of NumbersrealIyxiang#WA 2ms3572kbC++142.6kb2023-09-10 14:58:342023-09-10 14:58:34

Judging History

你现在查看的是最新测评结果

  • [2023-09-10 14:58:34]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3572kb
  • [2023-09-10 14:58:34]
  • 提交

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, 0, (int)x.size() - 1)
		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()) + 2, 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) 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;
	int len = n / (K + 1);
	string ans; bool fl = 0;
	int t = 1; rep(i, 1, K + 1) t = t * 3;
	auto calc = [&](int x) {
		int ret = 0; while(x > 0) ret += x % 3 - 1, x /= 3;
		return ret;
	};
	rep(s, 0, t - 1) if(calc(s) + len * (K + 1) == n) {
		vec pot(K + 1, len); int x = s;
		rep(j, 0, K) pot[j] += x % 3 - 1, x /= 3;
		int fl = 0;
		rep(j, 0, K) if(pot[j] <= 0) fl = 1;
		if(fl) continue;
		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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3572kb

input:

2
8 1
45455151
2 1
42

output:

55605
6

result:

wrong answer 1st lines differ - expected: '9696', found: '55605'