Submission #1022464

# Submission time Handle Problem Language Result Execution time Memory
1022464 2024-07-13T14:37:44 Z TroySer Unscrambling a Messy Bug (IOI16_messy) C++17
20 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#include "messy.h"

using namespace std;

vector<int> swappedBetween(string s) {

    vector<int> perm(s.size());
    for (int i = 0; i < s.size(); i++) {
        perm[i] = i;
    }

    vector<int> zeroes, ones;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '0') zeroes.push_back(i);
        else ones.push_back(i);
    }

    for (int i = 0; i < zeroes.size(); i++) {
        for (int j = 0; j < ones.size(); j++) {
            swap(s[zeroes[i]], s[ones[j]]);
            if (check_element(s)) {
                swap(perm[zeroes[i]], perm[ones[j]]);
                return perm;
            }
            swap(s[zeroes[i]], s[ones[j]]);
        }
    }

}

vector<int> restore_permutation(int n, int w, int r) {

    string toAdd[n-1];
    for (int i = 1; i <= n-1; i++) {
        string s = "";
        for (int j = 0; j < i; j++) {
            s += "1";
        }
        for (int j = i; j < 8; j++) {
            s += "0";
        }
        toAdd[i - 1] = s;
    }

    for (int i = 0; i < n-1; i++) {
        add_element(toAdd[i]);
    }
    // add_element("10000000");
    // add_element("11000000");
    // add_element("11100000");
    // add_element("11110000");
    // add_element("11111000");
    // add_element("11111100");
    // add_element("11111110");

    compile_set();

    vector<int> perm(n);
    for (int i = 0; i < n; i++) {
        perm[i] = i;
    }
    
    for (int i = 0; i < n-1; i++) {
        if (!check_element(toAdd[i])) {
            return swappedBetween(toAdd[i]);
        }
    }
    return perm;
}

Compilation message

messy.cpp: In function 'std::vector<int> swappedBetween(std::string)':
messy.cpp:9:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
messy.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < s.length(); i++) {
      |                     ~~^~~~~~~~~~~~
messy.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < zeroes.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~
messy.cpp:20:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for (int j = 0; j < ones.size(); j++) {
      |                         ~~^~~~~~~~~~~~~
messy.cpp:13:17: warning: control reaches end of non-void function [-Wreturn-type]
   13 |     vector<int> zeroes, ones;
      |                 ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB n = 8
2 Correct 1 ms 348 KB n = 8
3 Correct 0 ms 348 KB n = 8
4 Correct 0 ms 348 KB n = 8
5 Correct 1 ms 348 KB n = 8
6 Correct 0 ms 348 KB n = 8
7 Correct 0 ms 348 KB n = 8
8 Correct 1 ms 348 KB n = 8
9 Correct 1 ms 348 KB n = 8
10 Correct 1 ms 348 KB n = 8
11 Correct 0 ms 348 KB n = 8
12 Correct 0 ms 344 KB n = 8
13 Correct 0 ms 348 KB n = 8
14 Correct 0 ms 348 KB n = 8
15 Correct 1 ms 348 KB n = 8
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB grader returned WA
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB grader returned WA
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB grader returned WA
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB grader returned WA
2 Halted 0 ms 0 KB -