QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#650118#6621. Luggage Lockyeah14Compile Error//C++1710.8kb2024-10-18 13:06:142024-10-18 13:06:27

Judging History

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

  • [2024-10-18 13:06:27]
  • 评测
  • [2024-10-18 13:06:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull long long
#define PII  pair<int ,int>
const int INF = -1145141919810;
const int mod = 1e9 + 7;
const int N = 1e6 + 7;
int fp(int a, int x, int mod) {
	int ans = 1;
	while (x) {
		if (x & 1)ans *= a;
		ans %= mod;
		a *= a;
		a %= mod;
		x >>= 1;
	}
	return ans;
}


//map<char, int>p;
map<string, int>p;
void solve() {
	int a[4],b[4];
	int c[4],d[4];
	string s1, s2;
	cin >> s1 >> s2;
	for (int i = 0; i < 4; i++) {
		a[i] = s1[i] - '0';
		b[i] = s2[i] - '0';
		c[i] = b[i] - a[i];
		d[i] = c[i];
		if (abs(d[i]) > 5) {
			if (d[i] < 0)d[i] += 10;
			else d[i] -= 10;
		}
	}
	int ans = 0x3f3f3f;
	for (int k = 0; k < 16; k++) {
		int cc[4];
		int j = k;
		int f = 8;
		int sss = 0;
		for (int i = 0; i < 4; i++) {
			cc[i] = j % 2;
			j /= 2;
		}
		string ss;
		int tt[4];
		for (int i = 0; i < 4; i++) {
			if (cc[i] == 1) {
				if (c[i] > 0)d[i] = c[i] - 10;
				else if (c[i] < 0)d[i] = c[i] + 10;
			}
			else d[i] = c[i];
			char ch = '0' + d[i];
			ss += d[i];
			//tt[i] = d[i];
		}
		if (p.count(ss) != 0) {
			ans = min(ans, p[ss]);
			continue;
		}
		int s = 0, e = 0;
		int t = abs(d[0]);
		int res = 0;
		int minn = 0;
		//int minn;
		for (int i = 0; i < 4; i++) {
			if (i == 3) {
				if (e != 3)res += abs(d[i]) - minn;
				else {
					res += t - minn;
					s = e;
					t = 0;
				}
			}
			else if (d[i] * d[i + 1] > 0 && abs(d[i]) >= abs(d[i + 1]))
			{
				e = i + 1;
				t = max(t, abs(d[i + 1]));
				//minn = abs(d[i]);
			}
			else {
				if (e < s) {
					res += abs(d[i]) - minn;
					if (d[i] * d[i + 1] > 0)minn = abs(d[i]);
					else minn = 0;
					s = i + 1;
					t = abs(d[i + 1]);
					continue;
				}
				res += t - minn;
				s = e + 1;
				t = abs(d[i + 1]);
				if (d[i] * d[i + 1] > 0)minn = abs(d[i]);
				else minn = 0;
			}
		}
		
		p[ss] = res;
		ans = min(ans, res);
		/*cout << res<<" ";
		for (int i = 0; i < 4; i++) {
			cout << d[i] << " ";
		}
		cout << endl;*/
	 }
	cout << ans << endl;
}
//&&(((sum[n]+k)%mid==0)||(sum[n]/mid!=(sum[n]+k)/mid)||(mid-(sum[n]%mid)>=k))
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int t = 1;
	cin >> t;
	int k = t;
	//er(9e7);
	//cout <<  7*4% 10;
	while (t--) {
		//if (k == 100000)cout << k - t + 1 << " ";
		solve();
	}
	//pr[5216953]
}
//int n;
//cin >> n;
//for (int i = 1; i <= n; i++) {
//	cin >> a[i];
//}
//int maxx = 0, minn = INF;
//int sum = 0;
//for (int i = n; i <= 1; i++) {
//	sum += minn;
//	if (top == 0) {
//		minn = a[i];
//		st[top++] = a[i];
//	}
//	else {
//		if (a[i] > top && a[i] > minn)
//	}
//}
//cout << maxx - minn << endl;
//7 2 1 4 5 1 3 3
//4 1000 1000 1000 1000
//0、
/*int maxx1 = 1;
		if (d[0] * d[1] > 0 && d[1] * d[2] > 0 && d[3] * d[2] > 0) {
			int maxx = 0,mi=0;
			for (int i = 0; i < 4; i++) {
				if (maxx < abs(d[i])) {
					maxx = abs(d[i]);
					mi = i;
				}
				d[i] = abs(d[i]);
			}
			if (mi == 0) {
				if (d[1] >= d[2]) {
					if (d[2] >= d[3])res = maxx;
					else res = maxx + d[3] - d[2];
				}
				if (d[1] < d[2]){
					if (abs(d[2]) > d[3]) {
						res = maxx + d[2] - max(d[1], d[3]) - d[2];
					}
					else res = maxx - d[2] + d[3];
					}
			}
			if (mi == 1) {
				if (d[2] > d[3]) {
					res = maxx;
				}
				else res = maxx - d[2] + d[3];
			}
			if (mi == 2) {
				if (abs(d[0]) < abs(d[1])) {
					res = maxx;
				}
				else res = maxx - d[1] + d[0];
			}
			if (mi == 3) {
				reverse(d, d + 4);
				if (d[1] >= d[2]) {
					if (d[2] >= d[3])res = maxx;
					else res = maxx + d[3] - d[2];
				}
				if (d[1] < d[2]) {
					if (abs(d[2]) > d[3]) {
						res = maxx + d[2] - max(d[1], d[3]) - d[2];
					}
					else res = maxx - d[2] + d[3];
				}
			}
		}
		else if ((d[0] * d[1] > 0 && d[1] * d[2] <= 0 && d[2] * d[3]>0)) {
			res = max(abs(d[0]), abs(d[1])) + max(abs(d[2]), abs(d[3]));
		}
		else if ((d[0] * d[1] <= 0 && d[1] * d[2] > 0 && d[2] * d[3] > 0)) {
			for (int i = 0; i < 4; i++) {
					d[i] = abs(d[i]);
			}
			if (d[2] >= d[3] && d[2] >= d[1])res = d[2];
			else if (d[2] <= d[3] && d[1] <= d[2])res = d[3];
			else if (d[2] >= d[3] && d[1] <= d[2])res = d[1] - d[2] + d[3];
			else res = d[1];
			res += d[0];
		}
		else if ((d[0] * d[1] > 0 && d[1] * d[2] > 0 && d[2] * d[3] <= 0)) {
			reverse(d, d + 4);
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			if (d[2] >= d[3] && d[2] >= d[1])res = d[2];
			else if (d[2] <= d[3] && d[1] <= d[2])res = d[3];
			else if (d[2] >= d[3] && d[1] <= d[2])res = d[1] - d[2] + d[3];
			else res = d[1];
			res += d[0];
		}
		else if ((d[0] * d[1] <= 0 && d[1] * d[2] <= 0 && d[2] * d[3] <= 0)) {
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			res = d[0] + d[1] + d[2] + d[3];
		}
		else if ((d[0] * d[1] <= 0 && d[1] * d[2] <= 0 && d[2] * d[3] > 0)) {
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			res = d[0] + d[1] + max(d[2], d[3]);
		}
		else if ((d[0] * d[1] > 0 && d[1] * d[2] <= 0 && d[2] * d[3] <= 0)) {
			reverse(d, d + 4);
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			res = d[0] + d[1] + max(d[2], d[3]);
		}
		else if (((d[0] * d[1] <= 0 && d[1] * d[2] > 0 && d[2] * d[3] <= 0))) {
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			res = d[0] + d[3] + max(d[2], d[1]);
		}*/#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull long long
#define PII  pair<int ,int>
const int INF = -1145141919810;
const int mod = 1e9 + 7;
const int N = 1e6 + 7;
int fp(int a, int x, int mod) {
	int ans = 1;
	while (x) {
		if (x & 1)ans *= a;
		ans %= mod;
		a *= a;
		a %= mod;
		x >>= 1;
	}
	return ans;
}


//map<char, int>p;
map<string, int>p;
void solve() {
	int a[4],b[4];
	int c[4],d[4];
	string s1, s2;
	cin >> s1 >> s2;
	for (int i = 0; i < 4; i++) {
		a[i] = s1[i] - '0';
		b[i] = s2[i] - '0';
		c[i] = b[i] - a[i];
		d[i] = c[i];
		if (abs(d[i]) > 5) {
			if (d[i] < 0)d[i] += 10;
			else d[i] -= 10;
		}
	}
	int ans = 0x3f3f3f;
	for (int k = 0; k < 16; k++) {
		int cc[4];
		int j = k;
		int f = 8;
		int sss = 0;
		for (int i = 0; i < 4; i++) {
			cc[i] = j % 2;
			j /= 2;
		}
		string ss;
		int tt[4];
		for (int i = 0; i < 4; i++) {
			if (cc[i] == 1) {
				if (c[i] > 0)d[i] = c[i] - 10;
				else if (c[i] < 0)d[i] = c[i] + 10;
			}
			else d[i] = c[i];
			char ch = '0' + d[i];
			ss += d[i];
			//tt[i] = d[i];
		}
		if (p.count(ss) != 0) {
			ans = min(ans, p[ss]);
			continue;
		}
		int s = 0, e = 0;
		int t = abs(d[0]);
		int res = 0;
		int minn = 0;
		//int minn;
		for (int i = 0; i < 4; i++) {
			if (i == 3) {
				if (e != 3)res += abs(d[i]) - minn;
				else {
					res += t - minn;
					s = e;
					t = 0;
				}
			}
			else if (d[i] * d[i + 1] > 0 && abs(d[i]) >= abs(d[i + 1]))
			{
				e = i + 1;
				t = max(t, abs(d[i + 1]));
				//minn = abs(d[i]);
			}
			else {
				if (e < s) {
					res += abs(d[i]) - minn;
					if (d[i] * d[i + 1] > 0)minn = abs(d[i]);
					else minn = 0;
					s = i + 1;
					t = abs(d[i + 1]);
					continue;
				}
				res += t - minn;
				s = e + 1;
				t = abs(d[i + 1]);
				if (d[i] * d[i + 1] > 0)minn = abs(d[i]);
				else minn = 0;
			}
		}
		
		p[ss] = res;
		ans = min(ans, res);
		/*cout << res<<" ";
		for (int i = 0; i < 4; i++) {
			cout << d[i] << " ";
		}
		cout << endl;*/
	 }
	cout << ans << endl;
}
//&&(((sum[n]+k)%mid==0)||(sum[n]/mid!=(sum[n]+k)/mid)||(mid-(sum[n]%mid)>=k))
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int t = 1;
	cin >> t;
	int k = t;
	//er(9e7);
	//cout <<  7*4% 10;
	while (t--) {
		//if (k == 100000)cout << k - t + 1 << " ";
		solve();
	}
	//pr[5216953]
}
//int n;
//cin >> n;
//for (int i = 1; i <= n; i++) {
//	cin >> a[i];
//}
//int maxx = 0, minn = INF;
//int sum = 0;
//for (int i = n; i <= 1; i++) {
//	sum += minn;
//	if (top == 0) {
//		minn = a[i];
//		st[top++] = a[i];
//	}
//	else {
//		if (a[i] > top && a[i] > minn)
//	}
//}
//cout << maxx - minn << endl;
//7 2 1 4 5 1 3 3
//4 1000 1000 1000 1000
//0、
/*int maxx1 = 1;
		if (d[0] * d[1] > 0 && d[1] * d[2] > 0 && d[3] * d[2] > 0) {
			int maxx = 0,mi=0;
			for (int i = 0; i < 4; i++) {
				if (maxx < abs(d[i])) {
					maxx = abs(d[i]);
					mi = i;
				}
				d[i] = abs(d[i]);
			}
			if (mi == 0) {
				if (d[1] >= d[2]) {
					if (d[2] >= d[3])res = maxx;
					else res = maxx + d[3] - d[2];
				}
				if (d[1] < d[2]){
					if (abs(d[2]) > d[3]) {
						res = maxx + d[2] - max(d[1], d[3]) - d[2];
					}
					else res = maxx - d[2] + d[3];
					}
			}
			if (mi == 1) {
				if (d[2] > d[3]) {
					res = maxx;
				}
				else res = maxx - d[2] + d[3];
			}
			if (mi == 2) {
				if (abs(d[0]) < abs(d[1])) {
					res = maxx;
				}
				else res = maxx - d[1] + d[0];
			}
			if (mi == 3) {
				reverse(d, d + 4);
				if (d[1] >= d[2]) {
					if (d[2] >= d[3])res = maxx;
					else res = maxx + d[3] - d[2];
				}
				if (d[1] < d[2]) {
					if (abs(d[2]) > d[3]) {
						res = maxx + d[2] - max(d[1], d[3]) - d[2];
					}
					else res = maxx - d[2] + d[3];
				}
			}
		}
		else if ((d[0] * d[1] > 0 && d[1] * d[2] <= 0 && d[2] * d[3]>0)) {
			res = max(abs(d[0]), abs(d[1])) + max(abs(d[2]), abs(d[3]));
		}
		else if ((d[0] * d[1] <= 0 && d[1] * d[2] > 0 && d[2] * d[3] > 0)) {
			for (int i = 0; i < 4; i++) {
					d[i] = abs(d[i]);
			}
			if (d[2] >= d[3] && d[2] >= d[1])res = d[2];
			else if (d[2] <= d[3] && d[1] <= d[2])res = d[3];
			else if (d[2] >= d[3] && d[1] <= d[2])res = d[1] - d[2] + d[3];
			else res = d[1];
			res += d[0];
		}
		else if ((d[0] * d[1] > 0 && d[1] * d[2] > 0 && d[2] * d[3] <= 0)) {
			reverse(d, d + 4);
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			if (d[2] >= d[3] && d[2] >= d[1])res = d[2];
			else if (d[2] <= d[3] && d[1] <= d[2])res = d[3];
			else if (d[2] >= d[3] && d[1] <= d[2])res = d[1] - d[2] + d[3];
			else res = d[1];
			res += d[0];
		}
		else if ((d[0] * d[1] <= 0 && d[1] * d[2] <= 0 && d[2] * d[3] <= 0)) {
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			res = d[0] + d[1] + d[2] + d[3];
		}
		else if ((d[0] * d[1] <= 0 && d[1] * d[2] <= 0 && d[2] * d[3] > 0)) {
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			res = d[0] + d[1] + max(d[2], d[3]);
		}
		else if ((d[0] * d[1] > 0 && d[1] * d[2] <= 0 && d[2] * d[3] <= 0)) {
			reverse(d, d + 4);
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			res = d[0] + d[1] + max(d[2], d[3]);
		}
		else if (((d[0] * d[1] <= 0 && d[1] * d[2] > 0 && d[2] * d[3] <= 0))) {
			for (int i = 0; i < 4; i++) {
				d[i] = abs(d[i]);
			}
			res = d[0] + d[3] + max(d[2], d[1]);
		}*/

Details

answer.code:249:11: error: redefinition of ‘const long long int INF’
  249 | const int INF = -1145141919810;
      |           ^~~
answer.code:6:11: note: ‘const long long int INF’ previously defined here
    6 | const int INF = -1145141919810;
      |           ^~~
answer.code:250:11: error: redefinition of ‘const long long int mod’
  250 | const int mod = 1e9 + 7;
      |           ^~~
answer.code:7:11: note: ‘const long long int mod’ previously defined here
    7 | const int mod = 1e9 + 7;
      |           ^~~
answer.code:251:11: error: redefinition of ‘const long long int N’
  251 | const int N = 1e6 + 7;
      |           ^
answer.code:8:11: note: ‘const long long int N’ previously defined here
    8 | const int N = 1e6 + 7;
      |           ^
answer.code:252:5: error: redefinition of ‘long long int fp(long long int, long long int, long long int)’
  252 | int fp(int a, int x, int mod) {
      |     ^~
answer.code:9:5: note: ‘long long int fp(long long int, long long int, long long int)’ previously defined here
    9 | int fp(int a, int x, int mod) {
      |     ^~
answer.code:266:17: error: redefinition of ‘std::map<std::__cxx11::basic_string<char>, long long int> p’
  266 | map<string, int>p;
      |                 ^
answer.code:23:17: note: ‘std::map<std::__cxx11::basic_string<char>, long long int> p’ previously declared here
   23 | map<string, int>p;
      |                 ^
answer.code:267:6: error: redefinition of ‘void solve()’
  267 | void solve() {
      |      ^~~~~
answer.code:24:6: note: ‘void solve()’ previously defined here
   24 | void solve() {
      |      ^~~~~
answer.code:356:8: error: redefinition of ‘int main()’
  356 | signed main() {
      |        ^~~~
answer.code:113:8: note: ‘int main()’ previously defined here
  113 | signed main() {
      |        ^~~~