CSES - Aalto Competitive Programming 2024 - wk5 - Mon - Results
Submission details
Task:Sum of ones
Sender:aalto2024e_001
Submission time:2024-09-30 16:28:36 +0300
Language:C++ (C++11)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.01 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#13ACCEPTED0.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:52:20: warning: statement has no effect [-Wunused-value]
   52 | #define debug(...) 42
      |                    ^~
input/code.cpp:68:9: note: in expansion of macro 'debug'
   68 |         debug(b, ans);
      |         ^~~~~

Code

#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define int long long

string to_string(string s) {
    return '"' + s + '"';
}
 
string to_string(const char* s) {
    return to_string((string) s);
}
 
string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
 
void debug_out() {
    cerr << endl;
}
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int n;

void solve() {
    cin >> n;
    n += 1;
    
    int ans = 0;
    int cur = 2;
    for (int b = 0; b < 60; b++) {
        ans += (n / cur) * (cur / 2);
        if ((n % cur) != 0) {
            ans += max(0LL, (n % cur) - (cur / 2));
        }
        debug(b, ans);
        cur <<= 1;
    }
    cout << ans << '\n';
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
            
    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }
}

Test details

Test 1

Verdict: ACCEPTED

input
1

correct output
1

user output
1

Test 2

Verdict: ACCEPTED

input
2

correct output
2

user output
2

Test 3

Verdict: ACCEPTED

input
3

correct output
4

user output
4

Test 4

Verdict: ACCEPTED

input
4

correct output
5

user output
5

Test 5

Verdict: ACCEPTED

input
5

correct output
7

user output
7

Test 6

Verdict: ACCEPTED

input
6

correct output
9

user output
9

Test 7

Verdict: ACCEPTED

input
7

correct output
12

user output
12

Test 8

Verdict: ACCEPTED

input
8

correct output
13

user output
13

Test 9

Verdict: ACCEPTED

input
9

correct output
15

user output
15

Test 10

Verdict: ACCEPTED

input
10

correct output
17

user output
17

Test 11

Verdict: ACCEPTED

input
303021765044187

correct output
7250167017244884

user output
7250167017244884

Test 12

Verdict: ACCEPTED

input
390977392667778

correct output
9400236781929604

user output
9400236781929604

Test 13

Verdict: ACCEPTED

input
670904313808571

correct output
16399391652009372

user output
16399391652009372

Test 14

Verdict: ACCEPTED

input
704275111916256

correct output
17252936460583174

user output
17252936460583174

Test 15

Verdict: ACCEPTED

input
799807335176164

correct output
19646099779305746

user output
19646099779305746

Test 16

Verdict: ACCEPTED

input
852012055430877

correct output
21005540865890493

user output
21005540865890493

Test 17

Verdict: ACCEPTED

input
901305628563213

correct output
22232965316761961

user output
22232965316761961

Test 18

Verdict: ACCEPTED

input
917427461591619

correct output
22650112032503064

user output
22650112032503064

Test 19

Verdict: ACCEPTED

input
981787468874797

correct output
24322274256024775

user output
24322274256024775

Test 20

Verdict: ACCEPTED

input
1000000000000000

correct output
24784747400675348

user output
24784747400675348

Test 21

Verdict: ACCEPTED

input
989898989898989

correct output
24531282955144033

user output
24531282955144033