Accepted
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