社区讨论

洛谷的神奇内存分配机制

P8791 [蓝桥杯 2022 国 AC] 内存空间参与者 3已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@m311vndm
此快照首次捕获于
2024/11/03 11:46
去年
此快照最后确认于
2025/11/04 15:28
4 个月前
查看原帖

给大家看一段逆天代码

C
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
ll t, ans;
string s;

vector<string> split(string str, char sep=' ') {
	vector<string> ret;
	ll idx = 0, _idx = 0;
	while (idx < (ll)str.size()) {
		if (str[_idx] == sep) {
			ret.push_back(str.substr(idx, _idx - idx));
			idx = _idx + 1;
		}
		++_idx;
	}
	if (idx < (ll)str.size()) ret.push_back(str.substr(idx));
	return ret;
}

int main() {
	
	cin >> t;
	getline(cin, s);
	while (t--) {
		getline(cin, s);
		ll st = s.find(' ');
		string type = s.substr(0, st);
		if (type == "int") {
			ans += split(s, ',').size() * 4;
			continue;
		}
		if (type == "long") {
			ans += split(s, ',').size() * 8;
			continue;
		}
		if (type == "String") {
			vector<string> ret = split(s, '"');
			for (ll i = 1; i < (ll)ret.size(); i += 2) {
				ans += ret[i].size();
			}
			continue;
		}
		if (type == "int[]") {
			ll l = s.find('[', 4), r = s.find(']', 5);
			do {
				ans += atoi(s.substr(l + 1, r - l - 1).c_str()) * 4ll;
				l = s.find('[', r);
				r = s.find(']', l);
			} while (l != -1 && r != -1);
			continue;
		}
		if (type == "long[]") {
			ll l = s.find('[', 5), r = s.find(']', 6);
			do {
				ans += atoi(s.substr(l + 1, r - l - 1).c_str()) * 8ll;
				l = s.find('[', r);
				r = s.find(']', l);
			} while (l != -1 && r != -1);
			continue;
		}
	}
	if (ans / (1 << 30)) {
		cout << ans / (1 << 30) << "GB";
		ans %= 1ll << 30;
	}
	if (ans / (1 << 20)) {
		cout << ans / (1 << 20) << "MB";
		ans %= 1ll << 20;
	}
	if (ans / (1 << 10)) {
		cout << ans / (1 << 10) << "KB";
		ans %= 1ll << 10;
	}
	if (ans / (1 << 0)) {
		cout << ans / (1 << 0) << "B";
		ans %= 1ll << 0;
	}
	
	return 0;
}
你多交几次会发现它每次都会RE不同个数的点,我最多一次过了6个

回复

3 条回复,欢迎继续交流。

正在加载回复...