QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#552538 | #9255. Python Program | ucup-team008# | AC ✓ | 4ms | 3628kb | C++17 | 4.7kb | 2024-09-07 23:35:33 | 2024-09-07 23:35:34 |
Judging History
answer
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
#define f first
#define s second
#define derr if(0) cerr
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << flush;
// END NO SAD
template<class Fun>
class y_combinator_result {
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
template<class T>
bool updmin(T& a, T b) {
if(b < a) {
a = b;
return true;
}
return false;
}
template<class T>
bool updmax(T& a, T b) {
if(b > a) {
a = b;
return true;
}
return false;
}
typedef int64_t ll;
const int VARIABLE = 1e9;
ll arithsum(ll a, ll d, ll n) {
return a * n + n * (n - 1) / 2 * d;
}
ll rangesumfast(ll a, ll b, ll c) {
if(c > 0) {
if(a >= b) return 0;
// a + k * c < b
// k < (b - a) / c
ll numterms = (b - a - 1) / c + 1;
return arithsum(a, c, numterms);
}
assert(c < 0);
if(a <= b) return 0;
ll numterms = (a-b-1) / (-c) + 1;
return arithsum(a, c, numterms);
}
ll rangesumslow(ll a, ll b, ll c) {
if(c > 0) {
ll r = 0;
while(a < b) {
r += a;
a += c;
}
return r;
}
else {
assert(c < 0);
ll r = 0;
while(a > b) {
r += a;
a += c;
}
return r;
}
}
void readntokens(int n) {
string s;
while(n--) cin >> s;
}
array<int, 3> parse(string s) {
assert(s.substr(0, 6) == "range(");
s = s.substr(6, sz(s) - 8);
array<int, 3> ret;
ret[2] = 1;
int idx = 0;
while(sz(s)) {
int comma = 0;
while(comma < sz(s) && s[comma] != ',') comma++;
if(comma == 1 && (s[0] >= 'a' && s[0] <= 'z')) {
ret[idx++] = VARIABLE;
}
else {
ret[idx++] = stoi(s.substr(0, comma));
}
if(comma == sz(s)) break;
else s = s.substr(comma + 1);
}
return ret;
}
void solve() {
array<int, 3> aa, bb;
{
readntokens(4);
string a; cin >> a;
readntokens(3);
string b; cin >> b;
aa = parse(a);
bb = parse(b);
}
ll ret = 0;
while(true) {
auto& [a, b, c] = aa;
if(c > 0 && a >= b) break;
if(c < 0 && a <= b) break;
auto [d, e, f] = bb;
if(d == VARIABLE) d = a;
if(e == VARIABLE) e = a;
if(f == VARIABLE) f = a;
ret += rangesumfast(d, e, f);
a += c;
}
cout << ret << "\n";
}
// what would chika do
// are there edge cases (N=1?)
// are array sizes proper (scaled by proper constant, for example 2* for koosaga tree)
// integer overflow?
// DS reset properly between test cases
// are you doing geometry in floating points
// are you not using modint when you should
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 3560kb
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: 3504kb
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: 1ms
memory: 3560kb
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: 4ms
memory: 3628kb
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