/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 516.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 560.0 KiB
#6 Accepted 1ms 388.0 KiB
#7 Accepted 1ms 396.0 KiB
#8 Accepted 1ms 320.0 KiB
#9 Accepted 1ms 484.0 KiB
#10 Accepted 1ms 532.0 KiB

Code

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

typedef long long ll;

#define pb      push_back
#define debug   cout<<"check"<<endl;cout.flush();
#define all(x)  (x).begin(),(x).end()
#define endl    '\n'

const ll N=200005;
const ll mod=1000000007;
const ll INF=2e18L+5;

void solve(){
    ll n;string st;
    cin>>st;
    ll a1=-1,a2=-1;
    for(ll i=0;;i++){
        if(st[i]=='+'){
            if(a1==-1){
                a1=0;
                ll pw=1;
                for(ll j=i-1;j>=0;j--){
                    
                    a1+=(st[j]-'0')*pw;
                    pw*=10LL;
                }
            }
            else {
                a2=0;
                ll pw=1;
                for(ll j=i-1;j>=0;j--){
                    if(st[j]=='+')break;
                    a2+=(st[j]-'0')*pw;
                    pw*=10LL;
                }
                break;
            }
        }
    }
    ll d=a2-a1;
    cin>>n;
    // cout<<a1<<" "<<a2<<endl;
    // cout<<d<<endl;
    ll an=a1+(d*(n-1));
    cout<<((a1+an)*n)/2LL<<endl;
}

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

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 15:45:42
Judged At
2025-09-02 15:45:42
Judged By
Score
100
Total Time
1ms
Peak Memory
560.0 KiB