QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#637546 | #9255. Python Program | XiaoMo247# | WA | 3ms | 3664kb | C++14 | 11.1kb | 2024-10-13 13:17:35 | 2024-10-13 13:17:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2e5 + 5;
ll ans = 0;
string s, a, b, c1, c2;
ll calc1(ll a1, ll mx, ll d){
if(a1 > mx) return 0;
ll xs = (mx - a1) / d + 1;
ll an = a1 + (xs - 1) * d;
ll ret = (a1 + an) * xs / 2;
return ret;
}
ll calc2(ll a1, ll mn, ll d){
if(a1 < mn) return 0;
ll xs = (mn - a1) / d + 1;
ll an = a1 + (xs - 1) * d;
ll ret = (a1 + an) * xs / 2;
return ret;
}
int main(){
ios::sync_with_stdio(false);
cin >> s;
cin >> s >> a >> s >> c1;
cin >> s >> b >> s >> c2;
cin >> s;
cin >> s;
int v1 = 0, v2 = 0, idx1[5], idx2[5];
for(int i = 0; i < c1.size(); i ++){
if(c1[i] == ','){
v1 ++;
idx1[v1] = i;
}
}
for(int i = 0; i < c2.size(); i ++){
if(c2[i] == ','){
v2 ++;
idx2[v2] = i;
}
}
if(v1 == 1){
ll st1 = stoll(c1.substr(6, idx1[1] - 6));
ll ed1 = stoll(c1.substr(idx1[1] + 1, ((ll)c1.size() - 2) - idx1[1]));
if(st1 >= ed1){
cout << 0 << "\n";
return 0;
}
ll cz1 = ed1 - st1;
if(v2 == 1){
if(c2.substr(6, idx2[1] - 6) == a){
ll st2 = 0;
ll ed2 = stoll(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]));
ll ans = 0;
for(int i = st1; i < ed1; i ++){
if(i > (ed2 - 1)) continue;
ans += (i + ed2 - 1) * (ed2 - i) / 2;
}
cout << ans << "\n";
return 0;
}
if(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]) == a){
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = 0;
ll ans = 0;
for(int i = st1; i < ed1; i ++){
if(st2 > i) continue;
ans += (st2 + i) * (i - st2 + 1) / 2;
}
cout << ans << "\n";
return 0;
}
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = stoll(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]));
if(st2 >= ed2){
cout << 0 << "\n";
return 0;
}
ll cz2 = (st2 + ed2) * (ed2 - st2) / 2;
cout << cz1 * cz2 << "\n";
}
else{
if(c2.substr(6, idx2[1] - 6) == a){
ll st2 = 0;
ll ed2 = stoll(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1)) - 1;
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll ans = 0;
if(bc2 < 0){
for(int i = st1; i < ed1; i ++){
ans += calc2(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
else{
for(int i = st1; i < ed1; i ++){
ans += calc1(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
}
if(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1) == a){
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = 0;
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll ans = 0;
if(bc2 < 0){
for(int i = st1; i < ed1; i ++){
ans += calc2(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
else{
for(int i = st1; i < ed1; i ++){
ans += calc1(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
}
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = stoll(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1));
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll cz2 = 0;
if(st2 >= ed2 && bc2 > 0){
cout << 0 << "\n";
return 0;
}
if(st2 <= ed2 && bc2 < 0){
cout << 0 << "\n";
return 0;
}
if(bc2 < 0){
for(int i = st2; i > ed2; i += bc2){
cz2 += i;
}
}
else{
for(int i = st2; i < ed2; i += bc2){
cz2 += i;
}
}
cout << cz1 * cz2 << "\n";
}
}
else{
ll st1 = stoll(c1.substr(6, idx1[1] - 6));
ll ed1 = stoll(c1.substr(idx1[1] + 1, idx1[2] - idx1[1] - 1));
ll bc1 = stoll(c1.substr(idx1[2] + 1, ((ll)c1.size() - 2) - idx1[2]));
ll cz1 = 0;
if(st1 >= ed1 && bc1 > 0){
cout << 0 << "\n";
return 0;
}
if(st1 <= ed1 && bc1 < 0){
cout << 0 << "\n";
return 0;
}
if(bc1 < 0){
for(int i = st1; i > ed1; i += bc1){
cz1 += i;
}
}
else{
for(int i = st1; i < ed1; i += bc1){
cz1 += i;
}
}
if(v2 == 1){
if(c2.substr(6, idx2[1] - 6) == a){
ll st2 = 0;
ll ed2 = stoll(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]));
ll ans = 0;
if(bc1 < 0){
for(int i = st1; i > ed1; i += bc1){
if(i > (ed2 - 1)) continue;
ans += (i + ed2 - 1) * (ed2 - i) / 2;
}
}
else{
for(int i = st1; i < ed1; i += bc1){
if(i > (ed2 - 1)) continue;
ans += (i + ed2 - 1) * (ed2 - i) / 2;
}
}
cout << ans << "\n";
return 0;
}
if(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]) == a){
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = 0;
ll ans = 0;
if(bc1 < 0){
for(int i = st1; i > ed1; i += bc1){
if(st2 > i) continue;
ans += (st2 + i) * (i - st2 + 1) / 2;
}
}
else{
for(int i = st1; i < ed1; i += bc1){
if(st2 > i) continue;
ans += (st2 + i) * (i - st2 + 1) / 2;
}
}
cout << ans << "\n";
return 0;
}
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = stoll(c2.substr(idx2[1] + 1, ((ll)c2.size() - 2) - idx2[1]));
if(st2 >= ed2){
cout << 0 << "\n";
return 0;
}
ll cz2 = (st2 + ed2) * (ed2 - st2) / 2;
cout << cz1 * cz2 << "\n";
}
else{
if(c2.substr(6, idx2[1] - 6) == a){
ll st2 = 0;
ll ed2 = stoll(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1)) - 1;
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll ans = 0;
if(bc1 < 0){
if (bc2 < 0) {
for (int i = st1; i > ed1; i += bc1) {
ans += calc2(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
} else {
for (int i = st1; i > ed1; i += bc1) {
ans += calc1(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
}
else{
if (bc2 < 0) {
for (int i = st1; i < ed1; i += bc1) {
ans += calc2(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
else {
for (int i = st1; i < ed1; i += bc1) {
ans += calc1(i, ed2, bc2);
}
cout << ans << "\n";
return 0;
}
}
}
if(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1) == a){
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = 0;
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll ans = 0;
if(bc1 < 0){
if (bc2 < 0) {
for (int i = st1; i > ed1; i += bc1) {
ans += calc2(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
else {
for (int i = st1; i > ed1; i += bc1) {
ans += calc1(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
}
else{
if (bc2 < 0) {
for (int i = st1; i < ed1; i += bc1) {
ans += calc2(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
else {
for (int i = st1; i < ed1; i += bc1) {
ans += calc1(st2, i, bc2);
}
cout << ans << "\n";
return 0;
}
}
}
ll st2 = stoll(c2.substr(6, idx2[1] - 6));
ll ed2 = stoll(c2.substr(idx2[1] + 1, idx2[2] - idx2[1] - 1));
ll bc2 = stoll(c2.substr(idx2[2] + 1, ((ll)c2.size() - 2) - idx2[2]));
ll cz2 = 0;
if(st2 >= ed2 && bc2 > 0){
cout << 0 << "\n";
return 0;
}
if(st2 <= ed2 && bc2 < 0){
cout << 0 << "\n";
return 0;
}
if(bc2 < 0){
for(int i = st2; i > ed2; i += bc2){
cz2 += i;
}
}
else{
for(int i = st2; i < ed2; i += bc2){
cz2 += i;
}
}
cout << cz1 * cz2 << "\n";
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
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: 3568kb
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: -100
Wrong Answer
time: 3ms
memory: 3664kb
input:
ans=0 for i in range(1,1000000): for j in range(i,1,-1): ans+=j print(ans)
output:
166666666666500000
result:
wrong answer 1st lines differ - expected: '166666666665500001', found: '166666666666500000'