CSES - Leirikisa 2 - Results
Submission details
Task:Flash memory
Sender:MojoLake
Submission time:2023-04-18 17:35:57 +0300
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttimescore
#10.02 s0details
#20.02 s0details
#3--0details
#40.02 s0details
#5--0details
#6--0details
#70.02 s0details
#8--0details
#9--0details
#10--0details
#110.01 s0details
#12--0details
#13--0details
#14--0details
#15--0details
#16--0details
#17--0details
#18--0details
#19--0details
#20--0details

Compiler report

input/code.cpp: In function 'void decode()':
input/code.cpp:59:13: warning: unused variable 'ans' [-Wunused-variable]
   59 |         int ans = 0;
      |             ^~~

Code

#include <bits/stdc++.h>

#define debug(x) cout << #x << ": " << x << "\n"
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

const int N = 101;
const int M = 101;
const int inf = 1e9;
const ll LLinf = 1e16;


void encode(){

    int b, m;
    cin >> b >> m;

    while(1){
        int c;
        cin >> c;
        if(c == 0)exit(0);

        string s; cin >> s;
        string val; cin >> val;

        int start = 0;
        for(int i = 0; i < b/2; ++i){
            if(s[i] == '1')start = b/2;
        }
        if(start != 0){
            bool need_new = 0;
            for(int i = start; i < b; ++i){
                if(s[i] == '1')need_new = 1;
            }
            if(need_new){
                cout << 0 << endl;
                continue;
            }
        }
        for(int i = 0; i < m; ++i){
            s[i+start] = val[i];
        }
        cout << s << endl;
    }
}

void decode(){

    int b, m;
    cin >> b >> m;
    
    while(1){
        int c;
        cin >> c;
        if(c == 0)exit(0);
        string s; cin >> s;
        int ans = 0;

        bool zero = 1;
        for(int i = 0; i < b; ++i){
            if(s[i] == '1')zero = 0;
        }

        if(zero){
            cout << string(m, '0') << endl;
            continue;
        }

        int start = 0;
        for(int i = b/2; i < b; ++i){
            if(s[i] == '1')start = b/2;
        }

        string ret = "";
        for(int i = start; i < start + m; ++i){
            ret += string(1, s[i]);
        }
        cout << ret << endl;
    }
}

int main(){

    int t;
    cin >> t;
    if(t == 1)encode();
    else decode();


}

Test details

Test 1

Verdict:

input
16 8 4.062445024495069624056

correct output
(empty)

user output
Activating encoder mode
0
16 8
1
0000000000000000 10111110
...
Truncated

Test 2

Verdict:

input
32 8 12.264904841300964834177

correct output
(empty)

user output
Activating encoder mode
0
32 8
1
000000000000000000000000000000...
Truncated

Test 3

Verdict:

input
32 16 4.129591513707784802006

correct output
(empty)

user output
(empty)

Test 4

Verdict:

input
64 8 30.039277894268828900030

correct output
(empty)

user output
Activating encoder mode
0
64 8
1
000000000000000000000000000000...
Truncated

Test 5

Verdict:

input
64 16 12.953148094217360432715

correct output
(empty)

user output
(empty)

Test 6

Verdict:

input
64 32 4.073559788233661501537

correct output
(empty)

user output
(empty)

Test 7

Verdict:

input
128 8 69.777892228928747548775

correct output
(empty)

user output
Activating encoder mode
0
128 8
1
000000000000000000000000000000...
Truncated

Test 8

Verdict:

input
128 16 34.73179127514363524097...

correct output
(empty)

user output
(empty)

Test 9

Verdict:

input
128 32 13.95078898770563890866...

correct output
(empty)

user output
(empty)

Test 10

Verdict:

input
128 64 4.039918210604800133907

correct output
(empty)

user output
(empty)

Test 11

Verdict:

input
256 8 174.46804708607103851145...

correct output
(empty)

user output
Activating encoder mode
0
256 8
1
000000000000000000000000000000...
Truncated

Test 12

Verdict:

input
256 16 82.22261415140417733455...

correct output
(empty)

user output
(empty)

Test 13

Verdict:

input
256 32 37.62938226976920648891...

correct output
(empty)

user output
(empty)

Test 14

Verdict:

input
256 64 14.26346228205414057768...

correct output
(empty)

user output
(empty)

Test 15

Verdict:

input
256 128 4.01556909389394343085...

correct output
(empty)

user output
(empty)

Test 16

Verdict:

input
512 16 204.7462421274103461702...

correct output
(empty)

user output
(empty)

Test 17

Verdict:

input
512 32 91.77859514807311153984...

correct output
(empty)

user output
(empty)

Test 18

Verdict:

input
512 64 39.23027924214593871262...

correct output
(empty)

user output
(empty)

Test 19

Verdict:

input
512 128 15.0000000021676722686...

correct output
(empty)

user output
(empty)

Test 20

Verdict:

input
512 256 4.00542327711105546887...

correct output
(empty)

user output
(empty)