QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#657669#9255. Python ProgramxuemanWA 4ms3904kbC++238.0kb2024-10-19 15:13:042024-10-19 15:13:05

Judging History

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

  • [2024-10-19 15:13:05]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3904kb
  • [2024-10-19 15:13:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const int N = 1000 + 10;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;

#define int long long
char t[maxn];

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
    string s;
    char x, y;
    getline(cin, s);
    int a = 0, b = 0, c = 1, d = 0, e = 0, f = 1;
    {
        int op = 0;
        cin >> s >> x >> s >> t;
        int n = strlen(t);
        for (int i = 0; i < n; i++)
        {
            if (t[i] == ',')
                op++;
        }
        if (op == 1)
            sscanf(t, "range(%lld,%lld):", &a, &b);
        else
            sscanf(t, "range(%lld,%lld,%lld):", &a, &b, &c);
    }

    vector<int> pos;
    {
        int op = 0;
        cin >> s >> y >> s >> t;
        int n = strlen(t);
        bool ok = 0;
        string tmp = "";
        for (int i = 0; i < n; i++)
        {
            if (t[i] == ')')
            {
                if (tmp == "")
                    continue;
                pos.push_back(stoll(tmp));
                tmp = "";
                break;
            }
            if (ok)
            {
                if (t[i] == ',')
                {
                    if (tmp == "")
                        continue;
                    pos.push_back(stoll(tmp));
                    tmp = "";
                    op++;
                }
                else if (!isdigit(t[i]) && t[i] != '-')
                    pos.push_back(LLONG_MAX);
                else
                    tmp += t[i];
            }
            if (t[i] == '(')
                ok = 1;
        }
    }
    int wei1 = 0, wei2 = 0, wei3 = 0;
    if (pos.size() == 2)
        pos.push_back(-1);
    cin >> s;
    int mode = 0;
    if (s.back() == x)
        mode = 1;
    else
        mode = 2;
    cin >> s;

    d = pos[0], e = pos[1], f = pos[2];

    if (d == LLONG_MAX)
        wei1 = 1;
    if (e == LLONG_MAX)
        wei2 = 1;
    if (f == LLONG_MAX)
        wei3 = 1;

    // for (auto it : pos)
    //     cout << it << ' ';

    // return 0;

    auto solve = [&](ll x, ll y, ll k) -> ll
    {
        ll z, cnt;
        if (k > 0)
        {
            if (x >= y)
                return 0;
            z = (y - 1 - x) / k * k + x;
            cnt = (y - 1 - x) / k + 1;
        }
        else
        {
            if (x <= y)
                return 0;
            k = -k;
            z = x - (x - (y + 1)) / k * k;
            cnt = (x - (y + 1)) / k + 1;
            // cout << z << endl;
        }
        return (x + z) * cnt / 2;
    };

    auto solve1 = [&](ll x, ll y, ll k) -> ll
    {
        ll z, cnt;
        if (k > 0)
        {
            if (x >= y)
                return 0;
            z = (y - 1 - x) / k * k + x;
            cnt = (y - 1 - x) / k + 1;
        }
        else
        {
            if (x <= y)
                return 0;
            k = -k;
            z = x - (x - (y + 1)) / k * k;
            cnt = (x - (y + 1)) / k + 1;
            // cout <<
            // cout << z << ' ' << cnt << endl;
        }
        return cnt;
    };

    // cout << a << ' ' << b;
    // cout << c << endl;
    ll ans = 0;
    if (mode == 2)
    {
        if (c > 0)
        {
            // cout << a << ' ' << b << ' ' << c << endl;
            // cout << a << endl;
            for (int i = a; i < b; i += c)
            {
                // cout << i << endl;
                if (wei1)
                    d = i;
                if (wei2)
                    e = i;
                if (wei3)
                    f = i;
                // cout << d <<  ' ' << e << ' ' << f << endl;
                ans += solve(d, e, f);
                // cout << ans << endl;
            }
        }
        else
        {
            for (int i = a; i > b; i += c)
            {
                if (wei1)
                    d = i;
                if (wei2)
                    e = i;
                if (wei3)
                    f = i;
                ans += solve(d, e, f);
            }
        }
    }
    else
    {
        if (c > 0)
        {
            for (int i = a; i < b; i += c)
            {
                if (wei1)
                    d = i;
                if (wei2)
                    e = i;
                if (wei3)
                    f = i;
                ans += i * solve1(d, e, f);
                // cout << ans << endl;
            }
        }
        else
        {
            for (int i = a; i > b; i += c)
            {
                if (wei1)
                    d = i;
                if (wei2)
                    e = i;
                if (wei3)
                    f = i;
                ans += i * solve1(d, e, f);
            }
        }
    }

    auto show = [&]()
    {
        ll ans = 0;
        if (mode == 2)
        {
            if (c > 0)
            {
                // cout << a << ' ' << b << ' ' << c << endl;
                // cout << a << endl;
                for (int i = a; i < b; i += c)
                {
                    // cout << i << endl;
                    if (wei1)
                        d = i;
                    if (wei2)
                        e = i;
                    if (wei3)
                        f = i;
                    // cout << d <<  ' ' << e << ' ' << f << endl;
                    // ans += solve(d, e, f);
                    if (f > 0)
                    {
                        for (int j = d; j < e; j += f)
                            ans += j;
                    }
                    else
                    {
                        for (int j = d; j > e; j += f)
                            ans += j;
                    }
                    // cout << ans << endl;
                }
            }
            else
            {
                for (int i = a; i > b; i += c)
                {
                    if (wei1)
                        d = i;
                    if (wei2)
                        e = i;
                    if (wei3)
                        f = i;
                    if (f > 0)
                    {
                        for (int j = d; j < e; j += f)
                            ans += j;
                    }
                    else
                    {
                        for (int j = d; j > e; j += f)
                            ans += j;
                    }
                }
            }
        }
        else
        {
            if (c > 0)
            {
                for (int i = a; i < b; i += c)
                {
                    if (wei1)
                        d = i;
                    if (wei2)
                        e = i;
                    if (wei3)
                        f = i;
                    if (f > 0)
                    {
                        for (int j = d; j < e; j += f)
                            ans += j;
                    }
                    else
                    {
                        for (int j = d; j > e; j += f)
                            ans += j;
                    }
                }
            }
            else
            {
                for (int i = a; i > b; i += c)
                {
                    if (wei1)
                        d = i;
                    if (wei2)
                        e = i;
                    if (wei3)
                        f = i;
                    if (f > 0)
                    {
                        for (int j = d; j < e; j += f)
                            ans += i;
                    }
                    else
                    {
                        for (int j = d; j > e; j += f)
                            ans += i;
                    }
                }
            }
        }
        cout << "___" << ans << endl;
    };

    cout << ans << endl;
    // show();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3760kb

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

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

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: -100
Wrong Answer
time: 1ms
memory: 3728kb

input:

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

output:

0

result:

wrong answer 1st lines differ - expected: '11756963404587200', found: '0'