QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#584006 | #9255. Python Program | hos_lyric | AC ✓ | 41ms | 4092kb | C++14 | 2.8kb | 2024-09-23 03:17:39 | 2024-09-23 03:17:39 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
// floor(a / b)
Int divFloor(Int a, Int b) {
return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0);
}
// ceil(a / b)
Int divCeil(Int a, Int b) {
return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0);
}
char S[100'010];
vector<string> parse() {
int l, r;
for (l = 0; S[l] != '('; ++l) {}
for (r = 0; S[r] != ')'; ++r) {}
string s = string(S + (l + 1), S + r);
for (auto &c : s) if (c == ',') c = ' ';
istringstream iss(s);
vector<string> ret;
for (string a; iss >> a; ret.push_back(a)) {}
cerr<<ret<<endl;
return ret;
}
int main() {
fgets(S, sizeof(S), stdin);
fgets(S, sizeof(S), stdin); const auto I = parse();
fgets(S, sizeof(S), stdin); const auto J = parse();
Int ans = 0;
const Int A = stoi(I[0]);
const Int B = stoi(I[1]);
const Int C = (2 < I.size()) ? stoi(I[2]) : 1;
assert(C);
const Int K = (C > 0) ? divFloor(B - A - 1, C) : divFloor(A - B - 1, -C);
for (Int k = 0; k <= K; ++k) {
const Int i = A + k * C;
const Int D = islower(J[0][0]) ? i : stoi(J[0]);
const Int E = islower(J[1][0]) ? i : stoi(J[1]);
const Int F = (2 < J.size()) ? (islower(J[2][0]) ? i : stoi(J[2])) : 1;
assert(F);
const Int L = (F > 0) ? divFloor(E - D - 1, F) : divFloor(D - E - 1, -F);
// cerr<<i<<" "<<D<<" "<<E<<" "<<F<<endl;
/*
for (Int l = 0; l <= L; ++l) {
const Int j = D + l * F;
ans += j;
}
*/
if (L >= 0) {
ans += (L + 1) * D;
ans += L * (L + 1) / 2 * F;
}
}
printf("%lld\n", ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
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: 4092kb
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: 27ms
memory: 3728kb
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: 3748kb
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: 41ms
memory: 3748kb
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