/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 2ms 532.0 KiB
#6 Accepted 2ms 388.0 KiB
#7 Accepted 3ms 532.0 KiB
#8 Accepted 4ms 448.0 KiB
#9 Accepted 5ms 444.0 KiB
#10 Accepted 4ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pie 2*(acos(0.0))
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define endl "\n"
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define ALLAHU_AKBAR ios::sync_with_stdio(false); cin.tie(nullptr);
//typedef tree<ll, null_type, greater<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

void sir()
{
    string s; cin>>s;
    int n; cin>>n;
    string a = "";
    int pl = -1;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]=='+')
        {
            pl = i;
            break;
        }

        else a.pb(s[i]);
    }
    int n1 = 0;
    int x = 1;

    for(int i=a.length()-1; i>=0; i--)
    {
        n1 =+ (x *(a[i]-'0'));
        x *=10;
    }
    string b ="";
    pl++;
    //cout<<s[pl]<<endl;
    for(int i=pl; i<s.length(); i++)
    {
        if(s[i]=='+' || s[i]=='.')
        {
            break;
        }

        else b.pb(s[i]);
    }
    int n2 = 0;
    x = 1;
    for(int i=b.length()-1; i>=0; i--)
    {
        n2 =+ (x *(b[i]-'0'));
        x *=10;
    }
    n1 = stoi(a);
    n2 = stoi(b);
    //cout<<a<<" "<<b<<endl;
    int d = n2-n1;
    ll last = n1 + (n-1) * (ll)d;
    ll first = (ll)n1;
    //cout<<last<<endl;
    ll ans = ((ll)n*(first+last))/2;

    cout<<ans<<endl;
}

int main() {
    ALLAHU_AKBAR

    ll t = 1;
    //cin>>t;
    while(t--)
    {
        sir();
    }
    return 0;
}


Information

Submit By
Type
Submission
Problem
P1231 Busy Friend
Contest
LUCC Presents Kick & Code Intra LU Programming Contest
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-01 05:59:51
Judged At
2025-09-01 05:59:51
Judged By
Score
100
Total Time
5ms
Peak Memory
532.0 KiB