QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556363#9255. Python ProgramSLF666#WA 3ms3824kbC++203.1kb2024-09-10 17:20:102024-09-10 17:20:10

Judging History

This is the latest submission verdict.

  • [2024-09-10 17:20:10]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3824kb
  • [2024-09-10 17:20:10]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

#define endl "\n"
#define ll long long

vector<int> check(string s, char aa){
	vector<int>a;
	int x = 0;
	int flag = 1;
	for(int i=6;;i++){
//		cout<<s[i]<<endl;
		if(s[i] == ')'){
			a.push_back(flag * x);
			break;
		}
		else if(s[i] == ','){
			a.push_back(flag * x);
			flag = 1;
			x = 0;
		}
		else if(s[i] == '-'){
			flag = -1;
		}
		else if(s[i] == aa){
			x = -1;
			flag = 1;
		}
		else {
			x = x * 10 + (s[i] - '0');
		}
	}
	
	if(a.size() == 2)a.push_back(1);
	return a;
}

void solve(){
	ll ans = 0;
	vector<string>s(20);
	for(int i=1;i<=11;i++)cin>>s[i];
	
	for(int i=4;i<s[1].size();i++){
		int x = s[1][i] - '0';
		ans = ans * 10 + x;
	}	
	
	char a = s[3][0], b = s[7][0];
	char add = s[10][ s[10].size() - 1 ];
	
	vector<int>opa = check(s[5], a);
	vector<int>opb = check(s[9], a);
//	cout<<s[5]<<endl;
//	for(auto &x:opa)cout<<x<<" ";
//	cout<<endl;
//	cout<<s[9]<<endl;
//	for(auto &x:opb)cout<<x<<" ";
//	cout<<endl;

	if(opa[2] < 0){
		opa[2] *= -1;
		swap(opa[0], opa[1]);
		opa[0] += 1;
		opa[1] += 1;
	}
	
	for(int i=opa[0]; i < opa[1];i += opa[2]){
		
//		cout<<"i = "<<i<<endl;
		
		int x = i;
		
//		if(add == b){
	
			if(opb[0] == -1){//起点取i 
				
				if(opb[2] < 0 && x <= opb[1] || opb[2] > 0 && x >= opb[1]){
					continue;
				}
				
				int l = i, r = opb[1], d = abs(opb[2]);
				int cnt = (abs(l - r) + d - 1) / d;
				 
				r = i + (cnt - 1) * opb[2];
				
//				cout<<"l = "<<l<<" r = "<<r<<endl;
				
				if(add == b)ans += 1ll * (l + r) * cnt / 2;
				else ans += 1ll * cnt * i;
				
			}
			
			else if(opb[1] == -1){//最值取i 
				
				x = opb[0];
				
				int l = opb[0], r = i, d = opb[2];
				int dd = abs(d);
				
				if(d < 0){
					r += 1;
				}
				else r -= 1;
				
				//[l, r]
				
				if(d < 0 && l < r || d > 0 && l > r)continue;
				
				int cnt = (abs(l - r + 1) + dd - 1) / dd;
				
				r = l + (cnt - 1) * d;
				
				if(add == b)ans += 1ll * (l + r) * cnt / 2;
				else ans += 1ll * cnt * i;
			}
			
			else if(opb[2] == -1){//d为i 
				
				int l = opb[0], r = opb[1], d = i;
				
				r -= 1;
				
				if(l > r)continue;
				
				int cnt = (r - l + 1 + d - 1) / d;
				
				r = l + (cnt - 1) * d;
				
				if(add == b)ans += 1ll * (l + r) * cnt / 2;
				else ans += 1ll * cnt * i;
				
			}
			
			else {
				
				int l = opb[0], r = opb[1], d = opb[2];
				int dd = abs(d);
				
				if(d < 0){
					r += 1;
				}
				else r -= 1;
				
				int cnt = (abs(l - r + 1) + dd - 1) / dd;
				
				r = l + (cnt - 1) * d;
				
//				cout<<"l = "<<l<<" r = "<<r<<" cnt = "<<cnt<<endl; 
				
				if(add == b)ans += 1ll * (l + r) * cnt / 2;
				else ans += 1ll * cnt * i;
			}
			
//		}
		
	}
	
	cout<<ans<<endl;
}

/*
ans=0
for q in range(1,5,1):
for i in range(3,q,1):
ans+=q
print(ans)
*/

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t = 1;
//	cin>>t;
	for(int i=1;i<=t;i++){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

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: 3608kb

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: 3ms
memory: 3528kb

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: 3820kb

input:

ans=0
for i in range(31,321983,2):
    for j in range(313,382193):
        ans+=j
print(ans)

output:

11756840357269392

result:

wrong answer 1st lines differ - expected: '11756963404587200', found: '11756840357269392'