QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#553598#9255. Python ProgramzltAC ✓8ms8840kbC++143.9kb2024-09-08 16:23:372024-09-08 16:23:38

Judging History

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

  • [2024-09-08 16:23:38]
  • 评测
  • 测评结果:AC
  • 用时:8ms
  • 内存:8840kb
  • [2024-09-08 16:23:37]
  • 提交

answer

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

string s[99];

inline string work(string s) {
	int cnt = 0;
	for (char c : s) {
		cnt += (c == ',');
	}
	if (cnt == 2) {
		return s;
	}
	s.pop_back();
	s.pop_back();
	s += ",1):";
	return s;
}

inline int toint(string s) {
	int x = 0;
	bool f = (s[0] == '-');
	for (char c : s) {
		if (isdigit(c)) {
			x = x * 10 + c - '0';
		}
	}
	return f ? -x : x;
}

inline ll calc(ll l, ll r, ll k) {
	return (l + r) * ((r - l) / k + 1) / 2;
}

void solve() {
	for (int i = 0; i <= 10; ++i) {
		cin >> s[i];
		// cout << i << ' ' << s[i] << '\n';
	}
	s[4] = work(s[4]);
	s[8] = work(s[8]);
	s[4] = s[4].substr(6);
	s[8] = s[8].substr(6);
	for (char &c : s[4]) {
		if (c == ',' || c == ')' || c == ':') {
			c = ' ';
		}
	}
	for (char &c : s[8]) {
		if (c == ',' || c == ')' || c == ':') {
			c = ' ';
		}
	}
	int a, b, c;
	stringstream s1(s[4]);
	s1 >> a >> b >> c;
	vector<int> S;
	if (c > 0) {
		for (int i = a; i < b; i += c) {
			S.pb(i);
		}
	} else {
		for (int i = a; i > b; i += c) {
			S.pb(i);
		}
	}
	string d, e, f;
	stringstream s2(s[8]);
	s2 >> d >> e >> f;
	string I = s[2], J = s[6];
	if (d == I) {
		if (e == I) {
			puts("0");
			return;
		} else {
			if (f == I) {
				int E = toint(e);
				ll ans = 0;
				for (int i : S) {
					for (int j = i; j < E; j += i) {
						if (s[9].back() == I[0]) {
							ans += i;
						} else {
							ans += j;
						}
					}
				}
				printf("%lld\n", ans);
			} else {
				ll E = toint(e), F = toint(f), ans = 0;
				for (ll i : S) {
					if (F > 0) {
						if (i >= E) {
							continue;
						}
						ll up = i + (E - 1 - i) / F * F;
						if (s[9].back() == I[0]) {
							ans += i * ((up - i) / F + 1);
						} else {
							ans += calc(i, up, F);
						}
					} else {
						if (i <= E) {
							continue;
						}
						ll dw = i - (i - 1 - E) / (-F) * (-F);
						if (s[9].back() == I[0]) {
							ans += i * ((i - dw) / (-F) + 1);
						} else {
							ans += calc(dw, i, -F);
						}
					}
				}
				printf("%lld\n", ans);
			}
		}
	} else if (e == I) {
		if (f == I) {
			int D = toint(d);
			ll ans = 0;
			for (int i : S) {
				if (s[9].back() == I[0]) {
					ans += i;
				} else {
					ans += D;
				}
			}
			printf("%lld\n", ans);
		} else {
			ll D = toint(d), F = toint(f), ans = 0;
			for (ll i : S) {
				if (F > 0) {
					if (D >= i) {
						continue;
					}
					ll up = D + (i - 1 - D) / F * F;
					if (s[9].back() == I[0]) {
						ans += i * ((up - D) / F + 1);
					} else {
						ans += calc(D, up, F);
					}
				} else {
					if (D <= i) {
						continue;
					}
					ll dw = D - (D - 1 - i) / (-F) * (-F);
					if (s[9].back() == I[0]) {
						ans += i * ((D - dw) / (-F) + 1);
					} else {
						ans += calc(dw, D, -F);
					}
				}
			}
			printf("%lld\n", ans);
		}
	} else if (f == I) {
		ll D = toint(d), E = toint(e), ans = 0;
		for (ll i : S) {
			for (ll j = D; j < E; j += i) {
				if (s[9].back() == I[0]) {
					ans += i;
				} else {
					ans += j;
				}
			}
		}
		printf("%lld\n", ans);
	} else {
		ll D = toint(d), E = toint(e), F = toint(f), ans = 0;
		vector<ll> T;
		if (F > 0) {
			for (ll i = D; i < E; i += F) {
				T.pb(i);
			}
		} else {
			for (ll i = D; i > E; i += F) {
				T.pb(i);
			}
		}
		if (s[9].back() == I[0]) {
			for (ll i : S) {
				ans += i * ((ll)T.size());
			}
		} else {
			for (ll i : T) {
				ans += i * ((ll)S.size());
			}
		}
		printf("%lld\n", ans);
	}
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3808kb

input:

ans=0
for a in range(1,3):
    for b in range(5,1,-2):
        ans+=b
print(ans)

output:

16

result:

ok single line: '16'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4084kb

input:

ans=0
for q in range(100,50,-1):
    for i in range(q,77,20):
        ans+=i
print(ans)

output:

2092

result:

ok single line: '2092'

Test #3:

score: 0
Accepted
time: 4ms
memory: 8616kb

input:

ans=0
for i in range(1,1000000):
    for j in range(i,1,-1):
        ans+=j
print(ans)

output:

166666666665500001

result:

ok single line: '166666666665500001'

Test #4:

score: 0
Accepted
time: 2ms
memory: 8160kb

input:

ans=0
for i in range(31,321983,2):
    for j in range(313,382193):
        ans+=j
print(ans)

output:

11756963404587200

result:

ok single line: '11756963404587200'

Test #5:

score: 0
Accepted
time: 8ms
memory: 8840kb

input:

ans=0
for i in range(1,1000000):
    for j in range(i,114514,-1):
        ans+=j
print(ans)

output:

160610445975856765

result:

ok single line: '160610445975856765'

Extra Test:

score: 0
Extra Test Passed