QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#791222 | #9255. Python Program | zhisheng | WA | 4ms | 4012kb | C++20 | 5.1kb | 2024-11-28 17:31:31 | 2024-11-28 17:31:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a,b,c,d,e,f;
int sum(int a1,int n,int d) {
int an = a1 + (n-1)*d;
return (a1 + an)*n/2;
}
int sti(string s) {
int res = 0;
reverse(s.begin(),s.end());
for(int i=0;i<s.size();i++) {
res += (s[i] - '0')*pow(10,i);
}
return res;
}
signed main() {
ios::sync_with_stdio(0),cin.tie(0);
auto solve = [&]() {
vector <string> s(10);
for(int i=1;i<=5;i++) {
getline(cin,s[i]);
// cout << a[i] << "\n";
}
int ans = 0;
c = 1,f = 1;
string x = "";x += s[2][4];
string tmp = "";
// cout << x << "\n";
int cnt = 0,p1,p2;
for(int i=0;i<s[2].size();i++) {
if(s[2][i] == '(') p1 = i;
if(s[2][i] == ')') p2 = i;
}
int f1=0,f2=0,f3 = 0;
int fla = 0;
for(int i=p1;i<=p2;i++) {
if(s[2][i] == '-') {
fla = 1;
i++;
}
if(s[2][i]>='0' && s[2][i]<='9' ) {
tmp += s[2][i];
}
else {
if(tmp.size() > 0) {
cnt ++ ;
if(cnt == 1) {
a = sti(tmp);
if(fla) {
a = -a;
}
}
else if(cnt == 2) {
b = sti(tmp);
if(fla) {
b = -b;
}
}
else if(cnt ==3 ) {
c= sti(tmp);
if(fla) {
c = -c;
}
}
}
tmp = "";
f = 0;
}
}
tmp = "";
cnt = 0;
for(int i=0;i<s[3].size();i++) {
if(s[3][i] == '(') p1 = i;
if(s[3][i] == ')') p2 = i;
}
for(int i=p1;i<=p2;i++) {
if(s[3][i] == '-') {
fla = 1;
i++;
}
if(s[3][i]>='0' && s[3][i]<='9' ) {
tmp += s[3][i];
}
else if(s[3][i] >='a' && s[3][i]<='z') {
tmp += s[3][i];
}
else {
if(tmp.size() > 0) {
cnt ++ ;
// cout << tmp << "\n";
if(cnt == 1) {
if(tmp == x) {
f1 = 1;
}
else d = sti(tmp);
if(fla) {
d = -d;
}
}
else if(cnt == 2) {
if(tmp == x) {
f2 = 1;
}
else e = sti(tmp);
if(fla) {
e = -e;
}
}
else if(cnt ==3 ) {
if(tmp == x) {
f3 = 1;
}
else f = sti(tmp);
if(fla) {
f = -f;
}
}
}
tmp = "";
fla = 0;
}
}
// cout << a << " " << b << ' ' << c << " " << d << " " <<e << " " << f << "\n";
if(a < b) {
for(int i=a;i<b;i+=c) {
int st = d;int ed = e;int len = f;
if(f1 == 1) st = i;
if(f2 == 1) ed = i;
if(f3 == 1) len = i;
if(len > 0) {
if(st >= ed) {
continue;
}
int ct = (ed - st + len-1)/len;
ans += sum(st,ct,len);
}
if(len < 0) {
if(st<=ed) continue;;
int ct = (-ed+ st + abs(len)-1)/abs(len);
ans += sum(st,ct,len);
}
}
cout << ans << "\n";
}
else {
for(int i=a;i>b;i+=c) {
int st = d;int ed = e;int len = f;
if(f1 == 1) st = i;
if(f2 == 1) ed = i;
if(f3 == 1) len = i;
if(len > 0) {
if(st >= ed) {
continue;
}
int ct = (ed - st + len-1)/len;
ans += sum(st,ct,len);
}
if(len < 0) {
if(st<=ed) continue;;
int ct = (-ed+ st + abs(len)-1)/abs(len);
ans += sum(st,ct,len);
}
}
cout << ans << "\n";
}
};
int t = 1;
// cin >> t;
while(t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
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: 4012kb
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: 3992kb
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: 3912kb
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'