QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#760981#9255. Python Programyzhx#AC ✓4ms3840kbC++174.1kb2024-11-18 20:28:472024-11-18 20:28:48

Judging History

你现在查看的是最新测评结果

  • [2024-11-18 20:28:48]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3840kb
  • [2024-11-18 20:28:47]
  • 提交

answer

#include <iostream>
#include <stdlib.h>
using namespace std;

using ll = long long;
string rev(string str){
   string res = "";
   for (int i = 0 ; i < str.size() ; i++) if (str[i] != ' ') res.push_back(str[i]);
   return res;
}

void slove(){
   string str;
   getline(cin , str);
    // cin >> str;
   str = rev(str);
   ll ans = 0;
   for (int i = 0 ; i < str.size() ; i++){
     if (str[i] == '=') {
        ans=stoll(str.substr(i + 1));
        break;
     }
   }

   // cout << "ans :" << ans << endl;


   char up , dow;
   ll a[3] = {1 , 1 , 1};
   ll b[3] = {1 , 1 , 1};

   bool isVar[3] = {0 , 0 , 0};
   
   getline(cin , str);
   str = rev(str);
   // cout << "tar : " << str << endl;
   for (int i = 0; i < str.size() ; i++){
      if (str[i] == 'f'){
        up = str[i + 3];
      //   cout << "up : " << up << endl;
      }
      else if (str[i] == '('){
         string tmp="";
         int nx = 0;
        //  cout << str.substr(i + 1)<<endl;
         for (int j = i + 1 ; j < str.size() ; j++){
            // if (tmp[j] != ',' && tmp[j] != ')')
            if (str[j] != ',' && str[j] != ')')
                tmp.push_back(str[j]);
            else {
                // cout << "sz:" << tmp.size() << tmp << endl;
               //  cout << tmp << endl;
                a[nx++] = stoll(tmp);
                tmp.clear();
                if (nx == 3 || str[j] == ')') break;
            }   

         }
        //  cout << "a : " << a[0] << " b : " << a[1] << " c : " << a[2] << endl;
         break;
      }
   }
   getline(cin , str);
   str = rev(str);
//    cout << "tar : " << str << endl;
//    cin >> str;

   // cout << "up : " << up << endl;
   for (int i = 0; i < str.size() ; i++){
      if (str[i] == 'f'){
         dow = str[i + 4];
      }
      else if (str[i] == '('){
         string tmp;
         int nx = 0;
         for (int j = i + 1 ; j <= str.size() ; j++){
            if (str[j] != ',' && str[j] != ')')
               tmp.push_back(str[j]);
            else {
               //  cout << tmp << endl;

                if (tmp[0] == up)
                  isVar[nx++] = 1;
               //  else if (!isdigit(tmp[0])){
               //      cout << "error";
               //      cout << " sz : " << tmp.size() << tmp << endl;
               //  }
                else
                  b[nx++] = stoll(tmp);
                
                tmp.clear();
                if (nx == 3 || str[j] == ')') break;
            }   
         }
         // cout << "isVar : " << isVar[0] << " " << isVar[1] << " " << isVar[2] << endl;
         // cout << "a : " << b[0] << " b : " << b[1] << " c : " << b[2] << endl;
         break;
      }
   }
   getline(cin , str);
   str = rev(str);
//    cin >> str;
   int type = 0;
   for (int i = 0; i < str.size() ; i++){
      if (str[i] == '='){
        if (str[i + 1] == up) type = 0;
        else type = 1;
        break;
      }
   }
   
   if ((a[2] < 0 && a[0] <= a[1]) || (a[2] > 0 && a[0] >= a[1])) {
      cout << ans << endl;
      return ;
   }

   for (ll i = a[0] ; (i - a[1]) * (a[0] - a[1]) > 0 ; i += a[2]){

      ll t[3] = {};
      if (isVar[0]) t[0] = i;
      else t[0] = b[0];
      if (isVar[1]) t[1] = i;
      else t[1] = b[1];
      if (isVar[2]) t[2] = i;
      else t[2] = b[2];
      
      
      if ((t[2] < 0 && t[0] <= t[1]) || (t[2] > 0 && t[0] >= t[1])) {
         continue;
      }

      
      if (type == 0){
          ans += i * (abs(t[0] - t[1]) + abs(t[2]) - 1) / abs(t[2]);
      }else{
          ll tim = (abs(t[0] - t[1]) + abs(t[2]) - 1) / abs(t[2]);
          
          ll qwq = (2 * t[0] + t[2] * (tim - 1)) * tim / 2LL;
         //  cout << "test : " << qwq << endl;
         //  cout << "t[0] : " << t[0] << " t[1] : " << t[1] << " t[2] : " << t[2] << "tim : " << tim << endl;
          ans += (2 * t[0] + t[2] * (tim - 1)) * tim / 2LL;
      }

      
   }

   cout << ans << endl;
}
int main(){
   // freopen("in.txt" , "r" , stdin);
   slove();
}

/*
ans=0
for a in range(1,3):
for b in range(5,1,-2):
ans+=b
print(ans)
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3608kb

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: 1ms
memory: 3840kb

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

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

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

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