CSES - Putka Open 2015 – 6/6 - Results
Submission details
Task:Bittilista
Sender:
Submission time:2015-12-04 23:33:45 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED17
#2ACCEPTED28
#3ACCEPTED55
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.05 s1details
#3ACCEPTED0.06 s1details
#4ACCEPTED0.05 s1details
#5ACCEPTED0.05 s1details
#6ACCEPTED0.04 s2details
#7ACCEPTED0.06 s2details
#8ACCEPTED0.05 s2details
#9ACCEPTED0.05 s2details
#10ACCEPTED0.06 s2details
#11ACCEPTED0.05 s3details
#12ACCEPTED0.05 s3details
#13ACCEPTED0.05 s3details
#14ACCEPTED0.06 s3details
#15ACCEPTED0.06 s3details

Compiler report

input/code.cpp: In function 'std::string to_string(int)':
input/code.cpp:88:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.length(); i++) t += s[s.length() - i - 1];
                       ^

Code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
#include <cstdlib>
#include <queue>

#define uint unsigned int
#define INF 999999999
#define ll long long
#define M 1000000007
#define E 0.0000001
#define N 1<<16;

using namespace std;

string to_string (const int n);
int stoi (const string s);

int gcd (const int a, const int b) {
    if (b == 0) {
        if (a != 0) return a;
        else return 1;
    }
    return gcd(b, a % b);
}

int main () {
    cin.sync_with_stdio(false);
    cin.tie(0);

    long long n, m;
    cin>>n>>m;

    if (m == 1) {
        for (int i = 0; i < n; i++) cout<<0;
        return 0;
    }
    if (m == (1<<(n - 1))) {
        for (int i = 0; i < n; i++) cout<<1;
        return 0;
    }
    m--;
    int x[n];
    for (int i = 1; i < n; i++) {
        x[n - 1 - i] = m % 2;
        m /= 2;
    }

    x[n - 1] = x[0];
    for (int i : x) cout<<i;
    cout<<endl;


    /*for (int i = 0; i < (1<<n); i++) {
        string s;
        int ti = i;
        for (int x = 0; x < n; x++) {
            string c = s;
            s = ('0' + (ti % 2));
            s += c;
            ti /= 2;
        }
        int io = 0;
        int oi = 0;
        for (int i = 0; i < n - 1; i++) {
            if (s[i] == '0' && s[i + 1] == '1') oi++;
            if (s[i] == '1' && s[i + 1] == '0') io++;
        }
        if (io == oi) {
            cout<<s<<endl;
        }
    }*/

    return 0;
}

string to_string (int n) {
    string s;
    string t;
    while (n) {
        s += (n % 10) + '0';
        n /= 10;
    }
    for (int i = 0; i < s.length(); i++) t += s[s.length() - i - 1];
    return t;
}

int stoi (const string s) {
    int n = 0;
    for (char c : s) n = (n * 10) + (c - '0');
    return n;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
10 54

correct output
0001101010

user output
0001101010

Test 2

Group: 1

Verdict: ACCEPTED

input
10 302

correct output
1001011011

user output
1001011011

Test 3

Group: 1

Verdict: ACCEPTED

input
10 241

correct output
0111100000

user output
0111100000

Test 4

Group: 1

Verdict: ACCEPTED

input
10 382

correct output
1011111011

user output
1011111011

Test 5

Group: 1

Verdict: ACCEPTED

input
10 138

correct output
0100010010

user output
0100010010

Test 6

Group: 2

Verdict: ACCEPTED

input
20 131002

correct output
00111111111101110010

user output
00111111111101110010

Test 7

Group: 2

Verdict: ACCEPTED

input
20 441567

correct output
11010111100110111101

user output
11010111100110111101

Test 8

Group: 2

Verdict: ACCEPTED

input
20 109770

correct output
00110101100110010010

user output
00110101100110010010

Test 9

Group: 2

Verdict: ACCEPTED

input
20 327308

correct output
10011111110100010111

user output
10011111110100010111

Test 10

Group: 2

Verdict: ACCEPTED

input
20 302918

correct output
10010011111010001011

user output
10010011111010001011

Test 11

Group: 3

Verdict: ACCEPTED

input
50 216967103451763

correct output
011000101010101001001011100100...

user output
011000101010101001001011100100...

Test 12

Group: 3

Verdict: ACCEPTED

input
50 236618662270629

correct output
011010111001101000001001101001...

user output
011010111001101000001001101001...

Test 13

Group: 3

Verdict: ACCEPTED

input
50 426560943304480

correct output
110000011111101000111010110000...

user output
110000011111101000111010110000...

Test 14

Group: 3

Verdict: ACCEPTED

input
50 294553802415801

correct output
100001011111001010010011011000...

user output
100001011111001010010011011000...

Test 15

Group: 3

Verdict: ACCEPTED

input
50 502225394100883

correct output
111001000110001010111011000110...

user output
111001000110001010111011000110...