CSES - Aalto Competitive Programming 2024 - wk5 - Mon - Results
Submission details
Task:Sum of ones
Sender:aalto2024e_002
Submission time:2024-09-30 16:53:50 +0300
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#10ACCEPTED0.00 sdetails
#110.00 sdetails
#120.01 sdetails
#130.00 sdetails
#140.00 sdetails
#150.00 sdetails
#160.00 sdetails
#170.00 sdetails
#180.00 sdetails
#190.00 sdetails
#200.00 sdetails
#210.00 sdetails

Compiler report

input/code.cpp: In function 'void Test()':
input/code.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen("temp\\in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N=1005;

void Test()
{
    freopen("temp\\in.txt", "r", stdin);
}
LL f[N], ans, k;
bool one[N];
int main()
{
    // Test();
    LL n;
    cin>>n; 

    f[1] = 1;
    for(int i=2; i<=60; i++)
    {
        f[i] = (f[i-1] << 1) + (1<<(i-1));
        // cout << f[i] <<endl;
    }
    while(n)
    {
        one[++k] = n%2;
        n/=2; 
    }

    int now=0;
    for(int i=k; i>=1; i--)
    {
        if(one[i])
        {
            // place 0
            ans += f[i-1] + now*(1<<(i-1));

            // place 1
            now++;
        }
    }

    cout<<ans+now;

    return 0;
}

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:

input
303021765044187

correct output
7250167017244884

user output
4545325463802176

Test 12

Verdict:

input
390977392667778

correct output
9400236781929604

user output
5864662654267518

Test 13

Verdict:

input
670904313808571

correct output
16399391652009372

user output
10063563272451539

Test 14

Verdict:

input
704275111916256

correct output
17252936460583174

user output
10564130488845290

Test 15

Verdict:

input
799807335176164

correct output
19646099779305746

user output
11997110919075414

Test 16

Verdict:

input
852012055430877

correct output
21005540865890493

user output
12780180279560894

Test 17

Verdict:

input
901305628563213

correct output
22232965316761961

user output
13519584776559213

Test 18

Verdict:

input
917427461591619

correct output
22650112032503064

user output
13761410927314667

Test 19

Verdict:

input
981787468874797

correct output
24322274256024775

user output
14726810512625372

Test 20

Verdict:

input
1000000000000000

correct output
24784747400675348

user output
15000000153613755

Test 21

Verdict:

input
989898989898989

correct output
24531282955144033

user output
14848485346766208