답안 #535555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535555 2022-03-10T13:36:50 Z Deepesson Data Transfer (IOI19_transfer) C++17
100 / 100
145 ms 2496 KB
#include <bits/stdc++.h>
#include "transfer.h"

std::vector<int> get_attachment(std::vector<int> source) {
    int escala=0;
    if(source.size()>100)escala=1;
    int lim=6;
    if(escala)lim=8;
    int xoro=0;
    int count=0;
  ///  std::cout<<"Get: "<<source.size()<<"\n";
    std::vector<int> g;
    for(int i=0;i!=source.size();++i){
        if(source[i]){xoro^=i+1;++count;}
    }
    g.push_back(count&1);
    for(int i=0;i!=lim;++i){
        if(xoro&(1<<i))g.push_back(1);else g.push_back(0);
    }
  ///  std::cout<<"Send: "<<g.size()<<"\n";
    return g;
}

std::vector<int> retrieve(std::vector<int> data) {
    int escala=0;
    if(data.size()>100)escala=1;
    int lim=6;
    if(escala)lim=8;
   /// std::cout<<"Size: "<<data.size()<<"\n";
    std::vector<int> primario,ajuda;
    for(int i=0;i!=data.size()-(lim+1);++i){
        primario.push_back(data[i]);
    }
    for(int i=data.size()-(lim+1);i!=data.size();++i){
        ajuda.push_back(data[i]);
    }
    int xoresperado=0,countesperado=ajuda[0];
    for(int i=1;i!=ajuda.size();++i){
        if(ajuda[i])xoresperado+=(1<<(i-1));
    }
    int xoro=0,count=0;
    for(int i=0;i!=primario.size();++i){
        if(primario[i]){xoro^=i+1;++count;}
    }
    bool check1=xoro==xoresperado;
    bool check2=(count&1)==(countesperado&1);
    ///Os dois checks estao corretos. O array eh igual.
    if(check1&&check2){
        return primario;
    }
    ///Os checks estao dando resultados distintos: um dos checks esta corrompido\
    ///Significa que o array esta intacto :p
    if(check1!=check2){
        return primario;
    }
    ///Se chegou aq eh pq o array esta errado
    int falta = xoresperado^xoro;
    primario[falta-1]=!primario[falta-1];
    return primario;
}

Compilation message

transfer.cpp:51:5: warning: multi-line comment [-Wcomment]
   51 |     ///Os checks estao dando resultados distintos: um dos checks esta corrompido\
      |     ^
transfer.cpp: In function 'std::vector<int> get_attachment(std::vector<int>)':
transfer.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i!=source.size();++i){
      |                 ~^~~~~~~~~~~~~~~
transfer.cpp: In function 'std::vector<int> retrieve(std::vector<int>)':
transfer.cpp:31:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i=0;i!=data.size()-(lim+1);++i){
      |                 ~^~~~~~~~~~~~~~~~~~~~~
transfer.cpp:34:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=data.size()-(lim+1);i!=data.size();++i){
      |                                   ~^~~~~~~~~~~~~
transfer.cpp:38:18: 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=1;i!=ajuda.size();++i){
      |                 ~^~~~~~~~~~~~~~
transfer.cpp:42:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i=0;i!=primario.size();++i){
      |                 ~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 636 KB Output is correct
2 Correct 4 ms 648 KB Output is correct
3 Correct 5 ms 660 KB Output is correct
4 Correct 5 ms 648 KB Output is correct
5 Correct 5 ms 640 KB Output is correct
6 Correct 5 ms 648 KB Output is correct
7 Correct 5 ms 648 KB Output is correct
8 Correct 4 ms 640 KB Output is correct
9 Correct 4 ms 640 KB Output is correct
10 Correct 4 ms 728 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 648 KB Output is correct
14 Correct 4 ms 640 KB Output is correct
15 Correct 4 ms 648 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 5 ms 648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 130 ms 2488 KB Output is correct
2 Correct 131 ms 2496 KB Output is correct
3 Correct 117 ms 2492 KB Output is correct
4 Correct 126 ms 2484 KB Output is correct
5 Correct 142 ms 2432 KB Output is correct
6 Correct 145 ms 2488 KB Output is correct
7 Correct 125 ms 2484 KB Output is correct
8 Correct 144 ms 2492 KB Output is correct
9 Correct 115 ms 2484 KB Output is correct
10 Correct 113 ms 2492 KB Output is correct
11 Correct 113 ms 2480 KB Output is correct
12 Correct 118 ms 2484 KB Output is correct
13 Correct 118 ms 2496 KB Output is correct
14 Correct 116 ms 2496 KB Output is correct
15 Correct 118 ms 2496 KB Output is correct
16 Correct 122 ms 2492 KB Output is correct
17 Correct 122 ms 2484 KB Output is correct
18 Correct 117 ms 2484 KB Output is correct
19 Correct 122 ms 2492 KB Output is correct