最后一个点 WA,求调
  • 板块P9390 金盏花
  • 楼主rainygame
  • 当前回复26
  • 已保存回复26
  • 发布时间2023/6/3 19:14
  • 上次更新2023/10/23 13:58:12
查看原帖
最后一个点 WA,求调
804607
rainygame楼主2023/6/3 19:14

RT。

#include <bits/stdc++.h>
using namespace std;
const string a = "100001", b = "999998";

string x, z;
long long zs;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> x >> z;
	zs = stoll(z);
	
	if (z.size() < 6 || (z.size() == 6 && z < x)){
		cout << stoll("100000" + x)-stoll(z);
		return 0;
	}
	if (z.size() == 13){
		cout << zs - stoll("999999"+x);
		return 0;
	}else if (z.size() == 12) x = z.substr(0, 6) + x;
	else{
		string tmp = "1";
		for (int i(1); i<=11-z.size(); ++i) tmp += '0';
		x = tmp + z.substr(0, z.size()-6) + x;
	}
	
//	cout << x << '\n';
	if (x.substr(0, 6) == "999999") cout << min(abs(stoll(x)-zs), abs(stoll(a+x.substr(6, 6))-zs));
	else if (x.substr(0, 6) == "100000") cout << min(abs(stoll(x)-zs), abs(stoll(b+x.substr(6, 6))-zs));
	else cout << min({abs(stoll(x)-zs), abs(stoll(to_string(stoll(x.substr(0, 6))+1)+x.substr(6, 6))-zs), abs(stoll(to_string(stoll(x.substr(0, 6))-1)+x.substr(6, 6))-zs)});
	
	return 0;
}
2023/6/3 19:14
加载中...