/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 320.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 1ms 520.0 KiB
#7 Accepted 1ms 532.0 KiB
#8 Accepted 1ms 532.0 KiB
#9 Accepted 1ms 532.0 KiB
#10 Accepted 1ms 532.0 KiB

Code

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

int main() {
    string s;
    int n;
    cin>>s>>n;
    vector<int> nums;
    string tp="";
    for(char c:s){
        if(isdigit(c)) tp+=c;
        else if(c=='+'){
          if(!tp.empty()) {
            nums.push_back(stoi(tp));
            tp="";
          }
        } 
        else if(c=='.') break;
    }
    if(!tp.empty()) nums.push_back(stoi(tp));

    int diff= nums[1]-nums[0];
    ll sum=0;
    int curr=nums[0];

    for(int i=0;i<n;i++){
      sum+=curr;
      curr+= diff;
    }
    cout<<sum<<endl;
}

Information

Submit By
Type
Submission
Problem
P1231 Busy Friend
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 16:06:30
Judged At
2025-09-02 16:06:30
Judged By
Score
100
Total Time
1ms
Peak Memory
532.0 KiB