답안 #679304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679304 2023-01-08T02:40:05 Z ar88lo Data Transfer (IOI19_transfer) C++14
100 / 100
132 ms 2548 KB
#include "transfer.h"

std::vector<int> get_attachment(std::vector<int> source) {

    int x,lg,cnt;
    std::vector<int> ret;
    cnt = x = 0; lg = (source.size() == 63)?6:8;
    for(int i = 1; i <= source.size(); i++){
        if(source[i-1]){
            x ^= i;
        }
    }

    while(x > 0){
        cnt += x%2;
        ret.push_back(x%2);
        x/=2;
    }
    while(ret.size() < lg){
        ret.push_back(0);
    }
    ret.push_back(cnt%2);
    return ret;
}

std::vector<int> retrieve(std::vector<int> data) {

    int a,x,k,lg,cnt;
    std::vector<int> ret;
    k = 1; lg = (data.size() == 70)?6:8;
    cnt = x = a = 0;
    for(int i = data.size() - lg - 1; i < data.size() - 1; i++){
        if(data[i]) cnt++;
        a += data[i]*k;
        k*=2;
    }

    for(int i = 0; i < data.size() - lg - 1; i++){
        ret.push_back(data[i]);
    }

    if(data[data.size()-1] == cnt%2){

        for(int i = 1; i <= data.size() - lg - 1; i++){
            if(data[i-1]){
                x ^= i;
            }
        }
        x = x^a;
        if(x!=0) ret[x-1] = !ret[x-1];

    }
    return ret;

}

Compilation message

transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i = 1; i <= source.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
transfer.cpp:19:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |     while(ret.size() < lg){
      |           ~~~~~~~~~~~^~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:32:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = data.size() - lg - 1; i < data.size() - 1; i++){
      |                                       ~~^~~~~~~~~~~~~~~~~
transfer.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i = 0; i < data.size() - lg - 1; i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~
transfer.cpp:44:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(int i = 1; i <= data.size() - lg - 1; i++){
      |                        ~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 732 KB Output is correct
2 Correct 4 ms 656 KB Output is correct
3 Correct 4 ms 732 KB Output is correct
4 Correct 5 ms 644 KB Output is correct
5 Correct 4 ms 644 KB Output is correct
6 Correct 5 ms 652 KB Output is correct
7 Correct 4 ms 644 KB Output is correct
8 Correct 4 ms 728 KB Output is correct
9 Correct 4 ms 732 KB Output is correct
10 Correct 5 ms 732 KB Output is correct
11 Correct 4 ms 736 KB Output is correct
12 Correct 4 ms 644 KB Output is correct
13 Correct 4 ms 644 KB Output is correct
14 Correct 4 ms 652 KB Output is correct
15 Correct 4 ms 652 KB Output is correct
16 Correct 4 ms 732 KB Output is correct
17 Correct 3 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 2496 KB Output is correct
2 Correct 131 ms 2496 KB Output is correct
3 Correct 110 ms 2496 KB Output is correct
4 Correct 106 ms 2480 KB Output is correct
5 Correct 114 ms 2500 KB Output is correct
6 Correct 132 ms 2488 KB Output is correct
7 Correct 108 ms 2488 KB Output is correct
8 Correct 106 ms 2488 KB Output is correct
9 Correct 101 ms 2500 KB Output is correct
10 Correct 105 ms 2488 KB Output is correct
11 Correct 100 ms 2456 KB Output is correct
12 Correct 102 ms 2452 KB Output is correct
13 Correct 106 ms 2456 KB Output is correct
14 Correct 101 ms 2496 KB Output is correct
15 Correct 102 ms 2500 KB Output is correct
16 Correct 104 ms 2484 KB Output is correct
17 Correct 116 ms 2492 KB Output is correct
18 Correct 108 ms 2548 KB Output is correct
19 Correct 105 ms 2456 KB Output is correct