CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:Uolevi
Submission time:2019-09-30 10:14:03 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.01 sdetails
#20.01 sdetails
#30.01 sdetails
#40.01 sdetails
#50.01 sdetails
#60.01 sdetails

Compiler report

input/code.cpp: In function 'int bini(std::__cxx11::string)':
input/code.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < a.size(); i++){
                  ~~^~~~~~~~~~

Code

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

int n; // Kertoo juttujen maara
int eka;
int toka;
string edellinen(string a){
  // Tarkoitus on loytaa suurin luku joka on pienempaa kuin a joka koostuu 1 ja
  if(a.size() == 0){
    return "";
  }
  int eka = a[0]-'0';
  if(eka >= 1){
    a.erase(a.begin());
    return '1' + edellinen(a);
  }else{
    a.erase(a.begin());
    return '0' + edellinen(a);
  }
}

int bini(string a){
  if(a == "1") return 2;
  reverse(a.begin(), a.end());
  int su = 1;
  if(a[0] == '1') su++;
  for(int i = 0; i < a.size(); i++){
    if(a[i] == '1'){
      su += (2<<(i-1));
    }
  }
  return su;
}

int main(){
  cin >> n;
  for(int i = 0; i < n; i++){
    bool bo = false;
    cin >> eka >> toka;
    string alasa = edellinen(to_string(eka));
    if(alasa == "0" || alasa == to_string(eka)){
      bo = true;
    }
    string alasb = edellinen(to_string(toka));
  //  cout << alasb << " " << alasa << ": " << bini(alasb) << " " << bini(alasa) << "\n";
    cout << bini(alasb) - bini(alasa) + bo << "\n";
  }
}

Test details

Test 1

Verdict: ACCEPTED

input
1

correct output

user output
1

Test 2

Verdict:

input
2

correct output
1 2 
2 1 

user output
1
1

Test 3

Verdict:

input
5

correct output
1 2 3 4 5 
2 1 4 3 6 
3 4 1 2 7 
4 3 2 1 8 
5 6 7 8 1 

user output
1
1
1
1
1

Test 4

Verdict:

input
42

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1
1
1
1
1
...

Test 5

Verdict:

input
99

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1
1
1
1
1
...
Truncated

Test 6

Verdict:

input
100

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
1
1
1
1
1
...
Truncated