/ SeriousOJ /

Record Detail

Accepted


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

Code

#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false)
#define ct cin.tie(nullptr)
#define ll long long
#define nl '\n'
#define newline cout<<'\n'
#define yes cout<<"YES"<<'\n'
#define no cout<<"NO"<<'\n'
using namespace std;

void solve()
{
    string s;
    getline(cin, s);
    int n;
    cin >> n;
    cin.ignore();
    string constructor = "";
    vector<ll> arr;

    for(int i = 0; i < s.size(); i++)
    {
        if(arr.size() == 2)
            break;
        if(s[i] >= '0' && s[i] <= '9')
            constructor += s[i];
        else
        {
            arr.push_back(stoll(constructor));
            constructor = "";
        }
    }

    ll dif=arr[1]-arr[0];
    ll sum = (n*(2*arr[0]+(n-1)*dif))/2;
    cout<<sum<<nl;
}

int main()
{
    fast;
    ct;
    //int t;
    //cin >> t;
    //cin.ignore();
    //while(t--)
    //{
        solve();
    //}
}

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:36:06
Judged At
2025-09-02 15:38:52
Judged By
Score
100
Total Time
2ms
Peak Memory
532.0 KiB