QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#549992 | #9255. Python Program | ucup-team896# | AC ✓ | 0ms | 3684kb | C++20 | 2.3kb | 2024-09-07 08:28:00 | 2024-09-07 08:28:01 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }
using namespace std;
char lst;
pii get() {
int res = 0, op = 0;
char ch = getchar();
if (ch != '-' && !isdigit(ch)) return lst = getchar(), pii(0, int(ch));
if (ch == '-') op = 1, ch = getchar();
while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
lst = ch;
return pii(1, op ? -res : res);
}
int main() {
char ch = getchar();
while (ch != 'r') ch = getchar();
ch = getchar();
int A = int(getchar());
while (ch != '(') ch = getchar();
int Al = get().se;
int Ar = get().se;
int Ad = 1;
if (lst == ',') Ad = get().se;
ch = getchar();
while (ch != '(') ch = getchar();
pii Bl = get(), Br = get(), Bd = pii(1, 1);
if (lst == ',') Bd = get();
auto getsum = [&](int L, int R, int D) {
ll res = 0;
if (D > 0) {
// for (int i = L; i < R; i += D) res += i;
if (R <= L) return 0ll;
int lim = R / D * D + (L % D + D) % D;
while (lim < R) lim += D;
while (lim >= R) lim -= D;
int l = L, r = lim, x = (r - l) / D + 1;
return 1ll * x * (l + r) / 2;
} else {
if (R >= L) return 0ll;
// cerr << L << " " << R << " " << D << endl;
D = -D;
int lim = R / D * D + (L % D + D) % D;
while (lim > R) lim -= D;
while (lim <= R) lim += D;
int l = lim, r = L, x = (r - l) / D + 1;
// cerr << l << " " << r << endl;
return 1ll * x * (l + r) / 2;
}
// cerr << res << endl;
return res;
};
auto calc = [&](int p) {
int L = (Bl.fi ? Bl.se : p);
int R = (Br.fi ? Br.se : p);
int D = (Bd.fi ? Bd.se : p);
return getsum(L, R, D);
};
ll ans = 0;
if (Ad > 0) {
for (int i = Al; i < Ar; i += Ad) {
ans += calc(i);
}
} else {
Ad = -Ad;
for (int i = Al; i > Ar; i -= Ad) {
ans += calc(i);
}
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3684kb
input:
ans=0 for a in range(1,3): for b in range(5,1,-2): ans+=b print(ans)
output:
16
result:
wrong answer 1st lines differ - expected: '6', found: '16'