QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#641068 | #9255. Python Program | hansue# | AC ✓ | 6ms | 3812kb | C++14 | 2.2kb | 2024-10-14 18:17:12 | 2024-10-14 18:17:12 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 100;
int a, b, c;
bool di, ei, fi;
int d, e, f;
int n;
char ich, jch, s[N + 3];
int getint(char *s, int &p){
int x = 0;
bool flag = false;
if(s[p] == '-'){
flag = true;
p++;
}
while(isdigit(s[p])){
x = (x << 3) + (x << 1) + s[p] - '0';
p++;
}
return flag?(-x):x;
}
LL F(LL x, LL y, LL z){
LL t = (abs(y - x) % abs(z) == 0)?((y - x) / z):((y - x) / z + 1);
return (x + x + (t - 1) * z) * t / 2;
}
int main(){
char ch;
while((ch = getchar()) != '\n');
n = 0;
while((s[n] = getchar()) != '\n')
n++;
s[n] = '\0';
ich = s[4];
int p = 15;
a = getint(s, p);
p++;
b = getint(s, p);
if(s[p] == ')')
c = 1;
else {
p++;
c = getint(s, p);
}
n = 0;
while((s[n] = getchar()) != '\n')
n++;
s[n] = '\0';
jch = s[8];
p = 19;
if(s[p] == ich){
di = true;
p++;
}
else {
di = false;
d = getint(s, p);
}
p++;
if(s[p] == ich){
ei = true;
p++;
}
else {
ei = false;
e = getint(s, p);
}
if(s[p] == ')'){
fi = false;
f = 1;
}
else {
p++;
if(s[p] == ich)
fi = true;
else {
fi = false;
f = getint(s, p);
}
}
LL ans = 0;
if(c > 0){
if(a >= b){
//no repeat
}
else {
for(int i = a; i < b; i += c){
if(di) d = i;
if(ei) e = i;
if(fi) f = i;
if(f > 0){
if(d >= e){
//no repeat
}
else {
ans += F(d, e, f);
}
}
else {
if(d <= e){
//no repeat
}
else {
ans += F(d, e, f);
}
}
// printf("F(%2lld,%2lld,%2d)=%2lld ans=>%lld\n", d, e, f, F(d, e, f), ans);
}
}
}
else {
if(a <= b){
//no repeat
}
else {
for(int i = a; i > b; i += c){
if(di) d = i;
if(ei) e = i;
if(fi) f = i;
if(f > 0){
if(d >= e){
//no repeat
}
else {
ans += F(d, e, f);
}
}
else {
if(d <= e){
//no repeat
}
else {
ans += F(d, e, f);
}
}
}
}
}
printf("%lld", ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 1ms
memory: 3728kb
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: 3ms
memory: 3796kb
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: 2ms
memory: 3680kb
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: 6ms
memory: 3800kb
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