QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#586779#9255. Python Programgaofeng#AC ✓49ms3800kbC++233.8kb2024-09-24 15:30:172024-09-24 15:30:18

Judging History

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

  • [2024-09-24 15:30:18]
  • 评测
  • 测评结果:AC
  • 用时:49ms
  • 内存:3800kb
  • [2024-09-24 15:30:17]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
// #define int long long
typedef pair<int,int> PII;
const int N = 1e6 + 10;
const int mod = 998244353;

using i64 = long long;
void solve() {
    string tmp; 
    vector<string> s(2);
    getline(cin, tmp);
    for (int i = 0; i < 2; i++) {
        getline(cin, s[i]);
    }
    vector<int> t;
    {  
        vector<int> z;
        int idx = s[0].find('(', 0);
        z.push_back(idx);
        idx = s[0].find(',', idx + 1);
        z.push_back(idx);
        if (s[0].find(',', idx + 1) == string::npos) {
            idx = s[0].find(')', idx + 1);
            z.push_back(idx);
        } else {
            idx = s[0].find(',', idx + 1);
            z.push_back(idx);
            idx = s[0].find(')', idx + 1);
            z.push_back(idx);
        }
        for (int i = 1; i < z.size(); i++) {
            t.push_back(stoll(s[0].substr(z[i - 1] + 1, z[i] - z[i - 1] - 1)));
        }
    }
    
    // bool ok = false; 
    // int last = 0;
    // for (auto c : s[0]) {
    //     if (c >= '0' && c <= '9') {
    //         ok = true;
    //         last = last * 10 + c - '0';
    //     } else {
    //         if (ok) {
    //             t.push_back(last);
    //             last = 0;
    //             ok = false;
    //         }
    //     }
    // }
    char id1 = s[0][4];
    i64 ans = 0;
    // {  
        vector<int> z;
        int idx = s[1].find('(', 0);
        z.push_back(idx);
        idx = s[1].find(',', idx + 1);
        z.push_back(idx);
        if (s[1].find(',', idx + 1) == string::npos) {
            idx = s[1].find(')', idx + 1);
            z.push_back(idx);
        } else {
            idx = s[1].find(',', idx + 1);
            z.push_back(idx);
            idx = s[1].find(')', idx + 1);
            z.push_back(idx);
        }
    // }
    // cerr << t[0] << ' ' << t[1] << ' ' << t[2] << ' ';
    int nx = (t.size() > 2 ? t[2] : 1);
    int i = t[0];
    // for (int i = t[0]; i < t[1]; i += nx) 
    while(1){
        if (nx < 0 && i <= t[1]) break;
        if (nx > 0 && i >= t[1]) break; 
        i64 d, val1, val2;
        if (z.size() == 4) {
            // cerr << s[1].substr(z[2] + 1, z[3] - z[2] - 1) << "\n";
            if (s[1].substr(z[2] + 1, z[3] - z[2] - 1)[0] == id1) d = i;
            else d = stoll(s[1].substr(z[2] + 1, z[3] - z[2] - 1));
        } else {
            d = 1;
        }
        if (s[1][z[0] + 1] == id1) {
            val1 = i;
            val2 = stoll(s[1].substr(z[1] + 1, z[2] - z[1] - 1));
        } else if (s[1][z[1] + 1] == id1) {
            
            val1 = stoll(s[1].substr(z[0] + 1, z[1] - z[0] - 1));
            val2 = i;
        } else {
            val1 = stoll(s[1].substr(z[0] + 1, z[1] - z[0] - 1));
            val2 = stoll(s[1].substr(z[1] + 1, z[2] - z[1] - 1));
        }
        
        if (d < 0) {
            val2++;
            if (val1 >= val2) {
                i64 cnt = abs(val2 - val1) / abs(d) + 1;
                ans += (val1 + val1 + d * (cnt - 1)) * abs(cnt) / 2;
            }
        } else {
            val2--;
            if (val1 <= val2) {
                // cerr << val1 << ' ' << val2 << ' ' << d << "\n";

                i64 cnt = abs(val2 - val1) / abs(d) + 1;
                // cerr << cnt << ' ';
                ans += (val1 + val1 + d * (cnt - 1)) * abs(cnt) / 2;
                // cerr << (val1 + val1 + d * cnt) * abs(cnt) / 2 << "\n";

            }
        }
        
        i += nx;
    }   
    // for (int i = 0; i < 2; i++) {
    //     cout << s[i] << "\n";
    // }
    cout << ans << "\n";

}

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

详细

Test #1:

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

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

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

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

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: 49ms
memory: 3604kb

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