답안 #824002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824002 2023-08-13T11:20:54 Z Amylopectin Flight to the Ford (BOI22_communication) C++17
0 / 100
23 ms 256 KB
#include"communication.h"
#include <stdio.h>
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int mxn = 510,lo = 2,see = 7634530;
int dran[mxn] = {}
,mat1[mxn] = {0,0,0,2,0,0,1,1,0,0,0,1,2,1,1,1}
,mat2[mxn] = {2,2,3,3,3,1,3,3,2,2,1,2,3,2,3,3}
,dn[4] = {0,15,9,6}
,che[4] = {0,14,6,8};
void encode(int n, int x) 
{
    int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
    ,cmid,fmid,cse,csen,of,clp,crp,flp,frp;
    while(1)
    {
        cmid = (cl+cr) / 2;
        fmid = (fl+fr) / 2;
        if(x <= cmid)
        {
            cse = 0;
        }
        else if(x <= cr)
        {
            cse = 1;
        }
        else if(x <= fmid)
        {
            cse = 2;
        }
        else 
        {
            cse = 3;
        }
        csen = 0;
        for(i=3; i>0; i--)
        {
            if((1<<i) & dn[cse])
            {
                cret = send(1);
            }
            else 
            {
                cret = send(0);
            }
            csen += (cret << i);
        }
        of = 0;
        for(i=0; i<4; i++)
        {
            if(csen == che[i])
            {
                of = 1;
                break;
            }
        }
        if(of == 0)
        {
            if(1 & dn[cse])
            {
                cret = send(1);
            }
            else 
            {
                cret = send(0);
            }
            csen += cret;
        }
        if(mat1[csen] == 0)
        {
            clp = cl;
            crp = cmid;
        }
        else if(mat1[csen] == 1)
        {
            clp = cmid+1;
            crp = cr;
        }
        else if(mat1[csen] == 2)
        {
            clp = fl;
            crp = fmid;
        }
        if(mat2[csen] == 1)
        {
            flp = cmid+1;
            frp = cr;
        }
        else if(mat2[csen] == 2)
        {
            flp = fl;
            frp = fmid;
        }
        else if(mat2[csen] == 3)
        {
            flp = fmid+1;
            frp = fr;
        }
        cl = clp;
        cr = crp;
        fl = flp;
        fr = frp;
        if(cl == cr && fl == fr)
        {
            break;
        }
    }
    return ;
}
std::pair<int, int> decode(int n) 
{
    int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
    ,cmid,fmid,cse,csen,of,clp,crp,flp,frp;
    while(1)
    {
        cmid = (cl+cr) / 2;
        fmid = (fl+fr) / 2;
        csen = 0;
        for(i=3; i>0; i--)
        {
            cret = receive();
            csen += (cret << i);
        }
        of = 0;
        for(i=0; i<4; i++)
        {
            if(csen == che[i])
            {
                of = 1;
                break;
            }
        }
        if(of == 0)
        {
            cret = receive();
            csen += cret;
        }
        if(mat1[csen] == 0)
        {
            clp = cl;
            crp = cmid;
        }
        else if(mat1[csen] == 1)
        {
            clp = cmid+1;
            crp = cr;
        }
        else if(mat1[csen] == 2)
        {
            clp = fl;
            crp = fmid;
        }
        if(mat2[csen] == 1)
        {
            flp = cmid+1;
            frp = cr;
        }
        else if(mat2[csen] == 2)
        {
            flp = fl;
            frp = fmid;
        }
        else if(mat2[csen] == 3)
        {
            flp = fmid+1;
            frp = fr;
        }
        cl = clp;
        cr = crp;
        fl = flp;
        fr = frp;
        if(cl == cr && fl == fr)
        {
            break;
        }
    }
    return {cl,fl};
}

Compilation message

communication.cpp: In function 'void encode(int, int)':
communication.cpp:16:11: warning: unused variable 'j' [-Wunused-variable]
   16 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |           ^
communication.cpp:16:13: warning: unused variable 'cn' [-Wunused-variable]
   16 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |             ^~
communication.cpp:16:16: warning: unused variable 'cm' [-Wunused-variable]
   16 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                ^~
communication.cpp:16:19: warning: unused variable 'fn' [-Wunused-variable]
   16 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                   ^~
communication.cpp:16:22: warning: unused variable 'fm' [-Wunused-variable]
   16 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                      ^~
communication.cpp:16:25: warning: unused variable 'cou' [-Wunused-variable]
   16 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                         ^~~
communication.cpp:16:38: warning: unused variable 'csta' [-Wunused-variable]
   16 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                                      ^~~~
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:115:11: warning: unused variable 'j' [-Wunused-variable]
  115 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |           ^
communication.cpp:115:13: warning: unused variable 'cn' [-Wunused-variable]
  115 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |             ^~
communication.cpp:115:16: warning: unused variable 'cm' [-Wunused-variable]
  115 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                ^~
communication.cpp:115:19: warning: unused variable 'fn' [-Wunused-variable]
  115 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                   ^~
communication.cpp:115:22: warning: unused variable 'fm' [-Wunused-variable]
  115 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                      ^~
communication.cpp:115:25: warning: unused variable 'cou' [-Wunused-variable]
  115 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                         ^~~
communication.cpp:115:38: warning: unused variable 'csta' [-Wunused-variable]
  115 |     int i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                                      ^~~~
communication.cpp:116:16: warning: unused variable 'cse' [-Wunused-variable]
  116 |     ,cmid,fmid,cse,csen,of,clp,crp,flp,frp;
      |                ^~~
communication.cpp: In function 'void encode(int, int)':
communication.cpp:106:27: warning: 'frp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  106 |         if(cl == cr && fl == fr)
      |                        ~~~^~~~~
communication.cpp:106:27: warning: 'flp' may be used uninitialized in this function [-Wmaybe-uninitialized]
communication.cpp:106:15: warning: 'crp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  106 |         if(cl == cr && fl == fr)
      |            ~~~^~~~~
communication.cpp:106:15: warning: 'clp' may be used uninitialized in this function [-Wmaybe-uninitialized]
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:175:21: warning: 'frp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  175 |         if(cl == cr && fl == fr)
      |            ~~~~~~~~~^~~~~~~~~~~
communication.cpp:180:18: warning: 'flp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  180 |     return {cl,fl};
      |                  ^
communication.cpp:175:9: warning: 'crp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  175 |         if(cl == cr && fl == fr)
      |         ^~
communication.cpp:180:18: warning: 'clp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  180 |     return {cl,fl};
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 236 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 256 KB Not correct
2 Halted 0 ms 0 KB -