QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#553844#9255. Python Program333zhanTL 0ms4088kbC++204.2kb2024-09-08 21:11:482024-09-08 21:11:48

Judging History

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

  • [2024-09-08 21:11:48]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:4088kb
  • [2024-09-08 21:11:48]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define db double
#define ll unsigned long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)

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 () {
	array <string, 6> s;
    for (int i = 1; i <= 5; i ++) {
        getline (cin, s[i]);
    }

    char c1 = s[2][4], c2 = s[3][4];//i, j
    
    int sum2 = count (s[2].begin (), s[2].end (), ',');
    int sum3 = count (s[3].begin (), s[3].end (), ',');

   // cerr << sum2 << " " << sum3 << '\n';

    int a1 = 0, a2 = 0, a3 = 1;//第一层循环
    int b1 = 0, b2 = 0, b3 = 1;//第二层循环
    bool ok1 = 0, ok2 = 0, ok3 = 0;//判断第二层循环是字母还是数字
    
//======================================================================
//第一层循环的处理
    int id21 = s[2].find ('('), id22 = s[2].find (',', id21);
    for (int i = id21 + 1; i < id22; i ++) {
        a1 = a1 * 10 + s[2][i] - '0';
    }
    int id23 = s[2].find (',', id22 + 1);
    if (id23 == -1) {
        int id24 = s[2].find (')', id22);
        for (int i = id22 + 1; i < id24; i ++) {
            a2 = a2 * 10 + s[2][i] - '0';
        }
    } else {
        for (int i = id22 + 1; i < id23; i ++) {
            a2 = a2 * 10 + s[2][i] - '0';
        }
        a3 = 0;
        int w = 1;
        int id24 = s[2].find (')', id22);
        if (s[2][id23 + 1] == '-') w = -1, id23 ++;
        for (int i = id23 + 1; i < id24; i ++) {
            a3 = a3 * 10 + s[2][i] - '0';
        }
        a3 *= w;
    }
//=============================================================================
//第二层循环的处理
    int id31 = s[3].find ('('), id32 = s[3].find (',', id31);
    if (id32 - id31 == 2 && s[3][id31 + 1] == c1) {
        ok1 = 1;
    } else {
        for (int i = id31 + 1; i < id32; i ++) {
            b1 = b1 * 10 + s[3][i] - '0';
        }
    }
    int id33 = s[3].find (',', id32 + 1);
    if (id33 == -1) {
        int id34 = s[3].find (')', id32);
        if (id34 - id32 == 2 && s[3][id32 + 1] == c1) {
            ok2 = 1;
        } else {
            for (int i = id32 + 1; i < id34; i ++) {
                b2 = b2 * 10 + s[3][i] - '0';
            }
        }
    } else {
        if (id33 - id32 == 2 && s[3][id32 + 1] == c1) {
            ok2 = 1;
        } else {
             for (int i = id32 + 1; i < id33; i ++) {
                b2 = b2 * 10 + s[3][i] - '0';
            }
        }

        b3 = 0;
        int id34 = s[3].find (')', id32);
        if (id34 - id33 == 2 && s[3][id33 + 1] == c1) {
            ok3 = 1;
        } else {
            int w = 1;
            if (s[3][id33 + 1] == '-') w = -1, id33 ++;
            for (int i = id33 + 1; i < id34; i ++) {
                b3 = b3 * 10 + s[3][i] - '0';
            }
            b3 *= w;
        }
    }

    int ans = 0;
    if (a3 > 0) {
        for (int i = a1; i < a2; i += a3) {
            int c1 = b1, c2 = b2, c3 = b3;
            if (ok1) c1 = i;
            if (ok2) c2 = i;
            if (ok3) c3 = i;
            if (c3 > 0) {
                for (int j = c1; j < c2; j += c3) {
                    ans += j;
                }
            } else {
                for (int j = c1; j > c2; j += c3) {
                    ans += j;
                }
            }
        }
    } else {
        for (int i = a1; i > a2; i += a3) {
            int c1 = b1, c2 = b2, c3 = b3;
            if (ok1) c1 = i;
            if (ok2) c2 = i;
            if (ok3) c3 = i;
             if (c3 > 0) {
                for (int j = c1; j < c2; j += c3) {
                    ans += j;
                }
            } else {
                for (int j = c1; j > c2; j += c3) {
                    ans += j;
                }
            }
        }
    }

    printf ("%lld\n", ans);
}

signed main () {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
	int TT = 1; 
//	TT = read ();
	while (TT --) solve ();
	return 0;
}

詳細信息

Test #1:

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

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

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: -100
Time Limit Exceeded

input:

ans=0
for i in range(1,1000000):
    for j in range(i,1,-1):
        ans+=j
print(ans)

output:


result: