QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#642495#9255. Python ProgramTMM233#AC ✓4ms3620kbC++203.1kb2024-10-15 14:35:022024-10-15 14:35:03

Judging History

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

  • [2024-10-15 14:35:03]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3620kb
  • [2024-10-15 14:35:02]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N = 5e3 + 10;
void solve()
{
    ll ans = 0;
    string s;
    // cin >> s;
    // cin >> s;
    getline(cin, s);
    getline(cin, s);
    // cout << s << endl;
    ll a, b, c, d, e, f;

    auto toint = [&](string s) -> ll
    {
        int flag = 1;
        if (s[0] == '-')
        {
            flag = -1;
        }
        if (s.length() > 9)
        {
            return flag * inf;
        }
        ll ret = 0;
        for (auto i : s)
        {
            if (isdigit(i))
                ret = ret * 10 + (i - '0');
        }
        return ret * flag;
    };
    int lst = s.find('(') + 1;
    int nxt = s.find(',', lst);
    a = toint(s.substr(lst, nxt - lst));
    lst = nxt + 1;
    if (s.find(',', lst) == string::npos)
    {
        nxt = s.find(')', lst);
        b = toint(s.substr(lst, nxt - lst));
        c = 1;
    }
    else
    {
        nxt = s.find(',', lst);
        b = toint(s.substr(lst, nxt - lst));
        lst = nxt + 1;
        nxt = s.find(')', lst);
        c = toint(s.substr(lst, nxt - lst));
    }
    bool flag = 0;
    // cin >> s;
    getline(cin, s);
    bool digd = 1, dige = 1, digf = 1;
    lst = s.find('(') + 1;
    nxt = s.find(',', lst);
    auto ss = s.substr(lst, nxt - lst);
    if (!isdigit(ss.back()))
    {
        digd = 0;
    }
    else
    {
        d = toint(ss);
    }
    lst = nxt + 1;
    if (s.find(',', lst) == string::npos)
    {
        nxt = s.find(')', lst);
        ss = s.substr(lst, nxt - lst);
        if (!isdigit(ss.back()))
        {
            dige = 0;
        }
        else
        {
            e = toint(ss);
        }
        f = 1;
    }
    else
    {
        nxt = s.find(',', lst);
        ss = s.substr(lst, nxt - lst);
        if (!isdigit(ss.back()))
        {
            dige = 0;
        }
        else
            e = toint(ss);
        lst = nxt + 1;
        nxt = s.find(')', lst);
        ss = s.substr(lst, nxt - lst);
        if (!isdigit(ss.back()))
        {
            digf = 0;
        }
        else
            f = toint(ss);
    }
    // cout << a << " " << b << " " << c << endl;
    // cout << digd << " " << d << endl;
    // cout << digf << " " << e << endl;
    // cout << digf << " " << f << endl;
    for (ll i = a; (c > 0 ? i < b : i > b); i += c)
    {
        if (!dige)
            e = i;
        if (!digd)
            d = i;
        if (!digf)
            f = i;
        // cout<<d<<" "<<e<<" "<<f<<endl;
        if (f > 0)
        {
            ll tot = max(0ll, e - d+f-1) / f;
            ans += 1ll * tot * (d + d + (tot - 1) * f) / 2;
        }
        else
        {
            ll tot = max(0ll, d - e-f-1) / (-f);
            ans += 1ll * tot * (d + d + (tot - 1) * f) / 2;
        }
        // cout<<ans<<endl;
    }
    cout << ans << "\n";
}

signed main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    int t = 1;
    while (t--)
    {
        solve();
    }
}

詳細信息

Test #1:

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

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

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

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: 1ms
memory: 3532kb

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: 3ms
memory: 3616kb

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