/ 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 1ms 532.0 KiB
#6 Accepted 1ms 368.0 KiB
#7 Accepted 1ms 532.0 KiB
#8 Accepted 1ms 484.0 KiB
#9 Accepted 1ms 496.0 KiB
#10 Accepted 1ms 532.0 KiB

Code

/* --- "Start your journey in the name of God." --- */
/* ----- Amit Bhowmik ----- */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using int128 = __int128;
using ull = unsigned long long;
using u32 = unsigned;
const ll mod = 1e9 + 7;
const ll mx = 1e7 + 123;
typedef vector<ll> vl;
#define nl '\n';
typedef long double ld;
#define PB push_back
#define F first
#define S second
#define sz(x) x.size()
#define mid(l,r) ((r+l)/2)
const double PI = acos(-1);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sqr(a) ((a) * (a))
#define YES cout << "YES" << nl;
#define NO cout << "NO" << nl;
#define lowerstr(x) transform(all(x),x.begin(), ::tolower)
#define upperstr(x) transform(all(x),x.begin(), ::toupper)

void solve() {
	string s;
	ll n;
	cin >> s >> n;

	vector<ll> v;
	string str = "";
	for (auto c : s) {
		if (isdigit(c)) {
			str += c;
		}
		else if (c == '+') {
			if (!str.empty()) {
				v.PB(stoll(str));
				str.clear();
			}
		}
	}
	if (!str.empty()) v.PB(stoll(str));

	ll a1 = v[0], a2 = v[1];
	ll d = a2 - a1;

	ll an = a1 + (n - 1) * d;
	cout << (a1 + an) * n / 2 << nl;
	return;
}
int main() {
	fast_io;
	// ll t; cin >> t;
	// while(t--)
	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:51:54
Judged At
2025-09-02 15:51:54
Judged By
Score
100
Total Time
1ms
Peak Memory
532.0 KiB