Submission #411319

# Submission time Handle Problem Language Result Execution time Memory
411319 2021-05-25T04:11:39 Z silxikys Broken Device (JOI17_broken_device) C++14
100 / 100
57 ms 2696 KB
#include "Annalib.h"
#include <vector>
#include <string>

void Anna(int N, long long X, int K, int P[]) {
    std::vector<int> blocked(N,-1);
    std::string ans;
    for (int i = 0; i < K; i++) {
        blocked[P[i]] = 0;
    }
    int pos = 0;
    for (int i = 0; i < N; i += 3) {
        int cnt = (blocked[i] == 0) + (blocked[i+1] == 0) + (blocked[i+2] == 0);
        if (cnt > 1/* || (X >> pos) == 0*/) {
            ans += "000";
        }
        else if (cnt == 1) {
            if (blocked[i] == 0) {
                if (!(1 & (X>>pos))) {
                    ans += "001";    
                }
                else {
                    ans += "010";
                }
                pos++;
            }
            else if (blocked[i+1] == 0) {
                if (!(1 & (X>>pos))) {
                    ans += "001";
                    pos++;
                }
                else {
                    pos++;
                    if (!(1 & (X>>pos))) {
                        ans += "100";
                    }
                    else {
                        ans += "101";
                    }
                    pos++;
                }
            }
            else {
                if (!(1 & (X>>pos))) {
                    ans += "110";
                }
                else {
                    ans += "010";
                }
                pos++;
            }
        }
        else {
            bool a = 1 & (X>>pos);
            bool b = 1 & (X>>(pos+1));
            int r = 2*a+b;
            if (r == 0) {
                ans += "011";
            }
            else if (r == 1) {
                ans += "111";
            }
            else if (r == 2) {
                ans += "100";
            }
            else {
                ans += "101";
            }
            pos += 2;        
        }
    }
    for (int i = 0; i < N; i++) {
        Set(i,ans[i]=='0'?0:1);            
    }
}
#include "Brunolib.h"
#include <vector>
#include <string>
#include <bits/stdc++.h>

long long Bruno(int N, int A[]) {
    std::string ans;
    for (int i = 0; i < N; i += 3) {
        int r = A[i] * 4 + A[i+1] * 2 + A[i+2];
        if (r == 0) continue;
        else if (r == 1) ans += "0";
        else if (r == 2) ans += "1";
        else if (r == 3) ans += "00";
        else if (r == 4) ans += "10";
        else if (r == 5) ans += "11";
        else if (r == 6) ans += "0";
        else if (r == 7) ans += "01";
        /*
        000 : x
        001 : 0
        010 : 1
        011 : 00
        100 : 10
        101 : 11
        110 : 0
        111 : 01
        */
    }
    /*
    std::cerr << "Encoded string: ";
    for (int i = 0; i < N; i++) {
        std::cerr << A[i];
    }
    std::cerr << '\n';
    std::cerr << "Bruno string:   " << ans << '\n';
    */
    long long res = 0;
    long long mult = 1;
    for (int i = 0; i < ans.size(); i++) {
        if (ans[i] == '1') res += mult;
        mult *= 2;
    }
    return res;
}

Compilation message

Bruno.cpp: In function 'long long int Bruno(int, int*)':
Bruno.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     for (int i = 0; i < ans.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2512 KB Output is correct - L* = 40
2 Correct 45 ms 2560 KB Output is correct - L* = 40
3 Correct 45 ms 2508 KB Output is correct - L* = 40
4 Correct 43 ms 2604 KB Output is correct - L* = 40
5 Correct 50 ms 2596 KB Output is correct - L* = 40
6 Correct 40 ms 2496 KB Output is correct - L* = 40
7 Correct 51 ms 2416 KB Output is correct - L* = 40
8 Correct 47 ms 2696 KB Output is correct - L* = 40
9 Correct 47 ms 2492 KB Output is correct - L* = 40
10 Correct 40 ms 2504 KB Output is correct - L* = 40
11 Correct 42 ms 2464 KB Output is correct - L* = 40
12 Correct 40 ms 2500 KB Output is correct - L* = 40
13 Correct 52 ms 2528 KB Output is correct - L* = 40
14 Correct 43 ms 2412 KB Output is correct - L* = 40
15 Correct 56 ms 2548 KB Output is correct - L* = 40
16 Correct 41 ms 2572 KB Output is correct - L* = 40
17 Correct 42 ms 2544 KB Output is correct - L* = 40
18 Correct 56 ms 2588 KB Output is correct - L* = 40
19 Correct 47 ms 2472 KB Output is correct - L* = 40
20 Correct 41 ms 2496 KB Output is correct - L* = 40
21 Correct 40 ms 2384 KB Output is correct - L* = 40
22 Correct 50 ms 2624 KB Output is correct - L* = 40
23 Correct 44 ms 2508 KB Output is correct - L* = 40
24 Correct 41 ms 2372 KB Output is correct - L* = 40
25 Correct 46 ms 2484 KB Output is correct - L* = 40
26 Correct 57 ms 2444 KB Output is correct - L* = 40
27 Correct 45 ms 2488 KB Output is correct - L* = 40
28 Correct 46 ms 2504 KB Output is correct - L* = 40
29 Correct 41 ms 2584 KB Output is correct - L* = 40
30 Correct 41 ms 2596 KB Output is correct - L* = 40
31 Correct 47 ms 2460 KB Output is correct - L* = 40
32 Correct 47 ms 2612 KB Output is correct - L* = 40
33 Correct 40 ms 2528 KB Output is correct - L* = 40
34 Correct 41 ms 2548 KB Output is correct - L* = 40
35 Correct 43 ms 2512 KB Output is correct - L* = 40
36 Correct 40 ms 2500 KB Output is correct - L* = 40
37 Correct 50 ms 2572 KB Output is correct - L* = 40
38 Correct 50 ms 2364 KB Output is correct - L* = 40
39 Correct 55 ms 2440 KB Output is correct - L* = 40
40 Correct 41 ms 2528 KB Output is correct - L* = 40