问__int128用快读快写有什么问题吗
  • 板块学术版
  • 楼主封禁用户
  • 当前回复10
  • 已保存回复10
  • 发布时间2024/8/12 11:25
  • 上次更新2024/8/12 12:40:10
查看原帖
问__int128用快读快写有什么问题吗
1308563
封禁用户楼主2024/8/12 11:25

rt,题目P1018 我把测试点下载后本地运行无误

输入
6 2
356510
输出
107100

输入

30 4
628662684655649547832394878852

输出

434521206431496192913414028832

代码

#include<bits/stdc++.h>
#define int __int128
using namespace std;
const int N = 2e1 + 5;
bool p[N];
int n,m,cnt;
string s;
template <typename T> inline void read(T &x) {
	x = 0;
	int t = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) {
		if(c == '-') {
			t = -1;
		}
	}
	for(; isdigit(c); c = getchar()) {
		x = (x << 1) + (x << 3) + (c ^ 48);
	}
	x = t * x;
}
template <typename T> void print(T x) {
	if (x < 0) {
		x *= -1;
		putchar('-');
	}
	if(x > 9) {
		print(x / 10);
	}
	putchar(x % 10 + 48);
}
int stn(int b,int e) {
	int ans = 0;
	for(int i = b; i <= e; i++) {
		int t = s[i] - '0';
		ans = ans * 10 + t;
	}
	return ans;
}
void dfs(int t) {
	if(t == m + 1) {
		int ans = 1;
		int b = 0,x = 0;
		for(int i = 0; i < n; i++) {
			if(p[i] == true) {
				ans *= stn(b,i);
				//	cout << stn(b,i) << ' ';
				b = i + 1;
				x++;
				if(x == m) {
					break;
				}
			}
		}

		ans *= stn(b,n - 1);
		//	cout << stn(b,n - 1);
		cnt = max(cnt,ans);
		//cout << "  " << cnt << endl;
	} else {
		for(int i = 0; i < n; i++) {
			if(p[i] == true) {
				continue;
			} else {
				p[i] = true;
				dfs(t + 1);
				p[i] = false;
			}
		}
	}
	return;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(nullptr);
	read(n);
	read(m);
	fill(p + 1,p + n + 1,0);
	cin >> s;
	dfs(1);
	print(cnt);
	return 0;
}
2024/8/12 11:25
加载中...