QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#559057#9255. Python Program333zhanAC ✓40ms3800kbC++202.0kb2024-09-11 19:56:212024-09-11 19:56:21

Judging History

This is the latest submission verdict.

  • [2024-09-11 19:56:21]
  • Judged
  • Verdict: AC
  • Time: 40ms
  • Memory: 3800kb
  • [2024-09-11 19:56:21]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

inline int read () {
    int w = 1, s = 0; char ch = getchar ();
    for (; ! isdigit (ch); ch = getchar ()) if (ch == '-') w = -1;
    for (; isdigit (ch); ch = getchar ()) s = (s << 1) + (s << 3) + (ch ^ 48);
    return s * w;
}

void solve () {
	string s;

    cin >> s;
    cin >> s;
    cin >> s;
    cin >> s;
    cin >> s;

    string a, b, c, d, e, f;

    int i;
    s = s.substr (6);
    s = s.substr (0, s.find (')'));
    i = s.find (',');
    a = s.substr (0, i);
    s = s.substr (i + 1);
    i = s.find (',');
    if (i == -1) {
        b = s;
        c = "1";
    } else {
        b = s.substr (0, i);
        c = s.substr (i + 1);
    }   
    
    cin >> s;
    cin >> s;
    cin >> s;
    cin >> s;

    s = s.substr (6);
    s = s.substr (0, s.find (')'));
    i = s.find (',');
    d = s.substr (0, i);
    s = s.substr (i + 1);
    i = s.find (',');
    if (i == -1) {
        e = s;
        f = "1";
    } else {
        e = s.substr (0, i);
        f = s.substr (i + 1);
    }   

    cin >> s;
    cin >> s;

    int ans = 0;
    int va = stoll (a);
    int vb = stoll (b);
    int vc = stoll (c);
    for (int i = va; (vc > 0 ? i < vb : i > vb); i += vc) {
        int vd = isalpha (d[0]) ? i : stoll (d);
        int ve = isalpha (e[0]) ? i : stoll (e);
        int vf = isalpha (f[0]) ? i : stoll (f);
        if (vf > 0) {
            if (vd < ve) {
                int k = (ve - vd - 1) / vf + 1;
                ans += k * vd + k * (k - 1) / 2 * vf;
            }
        } else {
            if (vd > ve) {
                int k = (vd - ve - 1) / -vf + 1;
                ans += k * vd + k * (k - 1) / 2 * vf;
            }
        }
    }

    cout << ans << '\n';
} 

signed main () {
	ios::sync_with_stdio (false);
    cin.tie (nullptr);
    
	int T = 1; 
	// cin >> T;
	// T = read ();

	while (T --) {
		solve ();
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3536kb

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: 32ms
memory: 3544kb

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: 9ms
memory: 3624kb

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: 40ms
memory: 3800kb

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