QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#555754 | #9255. Python Program | JZYZ# | AC ✓ | 3ms | 3884kb | C++14 | 3.3kb | 2024-09-10 09:17:45 | 2024-09-10 09:17:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std ;
typedef long long LL ;
const int N = 1e5+10 ;
string s ;
inline bool test( int c , int a , int b )
{
if( c > 0 ) {
if(a<b) return 1 ;
return 0 ;
}
return a>b ;
}
int main()
{
int a , b , c , d , e , f ;
char x ;
a=b=c=d=e=f=0 ;
for(int i = 1 ; i <= 5 ; i ++ ) {
getline(cin,s) ;
// cout << s << endl ;
if( i == 2 ) {
for(int j = 0 ; j < s.size() ; j ++ ) {
if( s[j]>='a' && s[j]<='z' && s[j-1] == ' ' && s[j+1] == ' ' ) x = s[j] ;
if( s[j]!='-' && (s[j]<'0'||s[j]>'9') ) continue ;
int x = 0 , f = 1 ;
if( s[j] == '-' ) {
f = -1 ;
j ++ ;
}
while( j<s.size() && s[j]>='0'&&s[j]<='9' ) {
x = x*10+(s[j]-'0') ;
j ++ ;
}
if( !a ) a = x*f ;
else if( !b ) b = x*f ;
else if( !c ) c = x*f ;
}
if( !c ) c = 1 ;
}
if( i == 3 ) {
// cout << x << endl ;
for(int j = 0 ; j < s.size() ; j ++ ) {
if( s[j]>='a' && s[j]<='z' && (s[j+1]==')'||s[j+1]==',') ) {
if( s[j]==x ) {
if( !d ) d = -1e7 ;
else if( !e ) e = -1e7 ;
else if( !f ) f = -1e7 ;
}
}
if( s[j]!='-' && (s[j]<'0'||s[j]>'9') ) continue ;
int x = 0 , fg = 1 ;
if( s[j] == '-' ) {
fg = -1 ;
j ++ ;
}
while( j<s.size() && s[j]>='0'&&s[j]<='9' ) {
x = x*10+(s[j]-'0') ;
j ++ ;
}
if( !d ) d = x*fg ;
else if( !e ) e = x*fg ;
else if( !f ) f = x*fg ;
}
if( !f ) f = 1 ;
}
}
// printf("%d %d %d , %d %d %d\n" , a , b , c , d , e , f ) ;
LL ans = 0 ;
if( e == -1e7 && d == -1e7 ) {
printf("0\n") ;
return 0 ;
}
if( f == -1e7 ) {
for(int i = a ;test(c,i,b) ; i += c ) {
for(int j = d ; test(i,j,e) ; j += i ) {
ans += j ;
}
}
printf("%lld\n" , ans ) ;
return 0 ;
}
if( d == -1e7 ) {
for(int i = a ; test(c,i,b) ; i += c ) {
if( f > 0 ) {
if( i >= e ) continue ;
int K = (e-i-1)/f ;
ans += 1LL*(K+1)*i + 1LL*K*(K+1)/2*f ;
}
else {
if( i <= e ) continue ;
int K = (i-e-1)/(-f) ;
ans += 1LL*(K+1)*i + 1LL*K*(K+1)/2*f ;
}
// cout << i << ' ' << ans << endl ;
}
printf("%lld" , ans ) ;
return 0 ;
}
else if( e == -1e7 ) {
for(int i = a ; test(c,i,b) ; i += c ) {
if( f > 0 ) {
if( d >= i ) continue ;
int K = (i-d-1)/f ;
ans += 1LL*(K+1)*d + 1LL*K*(K+1)/2*f ;
}
else {
if( d <= i ) continue ;
int K = (d-i-1)/(-f) ;
ans += 1LL*(K+1)*d + 1LL*K*(K+1)/2*f ;
}
}
printf("%lld" , ans ) ;
return 0 ;
}
else {
if( c > 0 ) {
if( f > 0 ) {
int tim = 0 ;
for( ; a < b ; a += c ) tim ++ ;
for( ; d < e ; d += f ) ans += d ;
printf("%lld" , ans*tim ) ;
}
else {
int tim = 0 ;
for( ; a < b ; a += c ) tim ++ ;
for( ; d > e ; d += f ) ans += d ;
printf("%lld" , ans*tim ) ;
}
}
else {
for( ; a <= b ; a += c ) {
if( f > 0 ) {
int tim = 0 ;
for( ; a > b ; a += c ) tim ++ ;
for( ; d < e ; d += f ) ans += d ;
printf("%lld" , ans*tim ) ;
}
else {
int tim = 0 ;
for( ; a > b ; a += c ) tim ++ ;
for( ; d > e ; d += f ) ans += d ;
printf("%lld" , ans*tim ) ;
}
}
}
}
return 0 ;
}
/*
ans=0
for a in range(1,3):
for b in range(-3,2,a):
ans+=b
print(ans)
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
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: 3816kb
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: 3800kb
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: 3884kb
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: 2ms
memory: 3796kb
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