QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#677263#9255. Python ProgramH_ZzZ#AC ✓28ms3808kbC++234.3kb2024-10-26 10:50:512024-10-26 10:51:09

Judging History

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

  • [2024-10-26 10:51:09]
  • 评测
  • 测评结果:AC
  • 用时:28ms
  • 内存:3808kb
  • [2024-10-26 10:50:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
int __ = 1,n;
using pii=pair<int,int>;
int clc(int a,int b,int c)
{
    if(a<=b&&c<0)return 0;
    if(a>=b&&c>0)return 0;
    int beg,end,t;
    beg=a;
    if(c>0)
    {
        t=(b-1-a)/c;
        end=a+t*c;
    }else
    {
        c=abs(c);
        t=(a-1-b)/c;
        end=a-t*c;
    }
    //cout<<beg<<" "<<end<<" "<<t<<endl;
    return (beg+end)*(t+1)/2;
}
int toint(string s)
{
    int ff = 1, res = 0;
    for(int i = 0; i < s.size(); ++ i)
    {
        if(s[i] == '-')
        {
            ff = -1;
            continue;
        }
        else
        {
            res *= 10;
            res += (s[i] - '0');
        }
    }
    return res * ff;
}
void solve(){
    string s[12];
    for(int i = 1; i <= 11; ++ i)
    {
        cin >> s[i];
        // cout << s[i] << '\n';
    }
    string num[6][5];
    int idx = 6;
    for( ; idx < s[5].size() && s[5][idx] != ','; ++ idx)
    {
        num[2][1] += s[5][idx];
    }
    idx ++;
    for( ; idx < s[5].size() && s[5][idx] != ',' && s[5][idx] != ')'; ++ idx)
    {
        num[2][2] += s[5][idx];
    }
    if(s[5][idx] != ')')
    idx ++;
    for( ; idx < s[5].size() && s[5][idx] != ')'; ++ idx)
    {
        num[2][3] += s[5][idx];
    }
    idx = 6;
    for( ; s[9][idx] != ','; ++ idx)
    {
        num[3][1] += s[9][idx];
    }
    idx ++;
    for( ; idx < s[9].size() && s[9][idx] != ',' && s[9][idx] != ')'; ++ idx)
    {
        num[3][2] += s[9][idx];
    }
    if(s[9][idx] != ')')
        idx++;
    for( ; idx < s[9].size() && s[9][idx] != ')'; ++ idx)
    {
        num[3][3] += s[9][idx];
    }
    idx = 0;
    for( ; idx < s[10].size(); ++ idx)
    {
        if(s[10][idx] == '=')
        {
            idx ++;
            break;
        }
    }
    string plus;
    for(int i = idx; i < s[10].size(); ++ i)
        plus += s[10][i];
    string val1 = s[3], val2 = s[7];
    int finalans = 0;
    if(num[2][3] == "") num[2][3] = "1";
    if(num[3][3] == "") num[3][3] = "1";
    int ibeg = toint(num[2][1]), iend = toint(num[2][2]), ip = toint(num[2][3]);

    // cout << num[2][1] << ' ' << num[2][2] << ' ' << ibeg << ' ' << iend << '\n';
    if(ip >= 0)
    {
        for(int i = ibeg; i < iend; i += ip)
        {
            int jbeg, jend, jp;
            if(num[3][1] == val1) jbeg = i;
            else jbeg = toint(num[3][1]);
            if(num[3][2] == val1) jend = i;
            else jend= toint(num[3][2]);
            if(num[3][3] == val1) jbeg = i;
            else jp = toint(num[3][3]);
            if(jp > 0 && jbeg >= jend) continue;
            if(jp < 0 && jbeg <= jend) continue;
            if(plus == val1)
            {
                int gap = abs(jend - jbeg) - 1;
                finalans += (gap/jp) * i;
            }
            else if(plus == val2)
            {
                finalans+=clc(jbeg,jend,jp);
            }
            else
            {
                int gap = abs(jend - jbeg) - 1;
                finalans += (gap/jp) * toint(plus);
            }
            //cout<<finalans<<endl;
        }
    }
    else
    {
        for(int i = ibeg; i > iend; i += ip)
        {
            int jbeg, jend, jp;
            if(num[3][1] == val1) jbeg = i;
            else jbeg = toint(num[3][1]);
            if(num[3][2] == val1) jend = i;
            else jend= toint(num[3][2]);
            if(num[3][3] == val1) jbeg = i;
            else jp = toint(num[3][3]);
            if(jp > 0 && jbeg >= jend) continue;
            if(jp < 0 && jbeg <= jend) continue;
            if(plus == val1)
            {
                int gap = abs(jend - jbeg) - 1;
                finalans += (gap/jp) * i;
            }
            else if(plus == val2)
            {
                finalans+=clc(jbeg,jend,jp);
            }
            else
            {
                int gap = abs(jend - jbeg) - 1;
                finalans += (gap/jp) * toint(plus);
            }
            //cout<<finalans<<endl;
        }

    }
    cout << finalans;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    // freopen("1.in.txt","r",stdin);
    // cin >> __;
    while (__--){
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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

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: 26ms
memory: 3540kb

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: 5ms
memory: 3808kb

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: 28ms
memory: 3608kb

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