답안 #824015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824015 2023-08-13T11:28:16 Z Amylopectin Flight to the Ford (BOI22_communication) C++17
74 / 100
2400 ms 2048 KB
#include"communication.h"
#include <stdio.h>
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <time.h>
using namespace std;
const long long mxn = 510,lo = 2,see = 7634530;
long long 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) 
{
    long long 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 = min(cmid+1,cr);
            crp = cr;
        }
        else if(mat1[csen] == 2)
        {
            clp = fl;
            crp = fmid;
        }
        if(mat2[csen] == 1)
        {
            flp = min(cmid+1,cr);
            frp = cr;
        }
        else if(mat2[csen] == 2)
        {
            flp = fl;
            frp = fmid;
        }
        else if(mat2[csen] == 3)
        {
            flp = min(fmid+1,fr);
            frp = fr;
        }
        cl = clp;
        cr = crp;
        fl = flp;
        fr = frp;
        if(cl == cr && fl == fr)
        {
            break;
        }
    }
    return ;
}
std::pair<int, int> decode(int n) 
{
    long long 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;
    int a1,a2;
    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 = min(cmid+1,cr);
            crp = cr;
        }
        else if(mat1[csen] == 2)
        {
            clp = fl;
            crp = fmid;
        }
        if(mat2[csen] == 1)
        {
            flp = min(cmid+1,cr);
            frp = cr;
        }
        else if(mat2[csen] == 2)
        {
            flp = fl;
            frp = fmid;
        }
        else if(mat2[csen] == 3)
        {
            flp = min(fmid+1,fr);
            frp = fr;
        }
        cl = clp;
        cr = crp;
        fl = flp;
        fr = frp;
        if(cl == cr && fl == fr)
        {
            break;
        }
    }
    a1 = cl;
    a2 = fl;
    return {a1,a2};
}

Compilation message

communication.cpp: In function 'void encode(int, int)':
communication.cpp:16:17: warning: unused variable 'j' [-Wunused-variable]
   16 |     long long 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 'cn' [-Wunused-variable]
   16 |     long long 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 'cm' [-Wunused-variable]
   16 |     long long 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 'fn' [-Wunused-variable]
   16 |     long long i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                         ^~
communication.cpp:16:28: warning: unused variable 'fm' [-Wunused-variable]
   16 |     long long i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                            ^~
communication.cpp:16:31: warning: unused variable 'cou' [-Wunused-variable]
   16 |     long long i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                               ^~~
communication.cpp:16:44: warning: unused variable 'csta' [-Wunused-variable]
   16 |     long long 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:17: warning: unused variable 'j' [-Wunused-variable]
  115 |     long long 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 'cn' [-Wunused-variable]
  115 |     long long 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 'cm' [-Wunused-variable]
  115 |     long long 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 'fn' [-Wunused-variable]
  115 |     long long i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                         ^~
communication.cpp:115:28: warning: unused variable 'fm' [-Wunused-variable]
  115 |     long long i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                            ^~
communication.cpp:115:31: warning: unused variable 'cou' [-Wunused-variable]
  115 |     long long i,j,cn,cm,fn,fm,cou = 0,cret,csta,cl = 1,cr = (n+1)/2,fl = cr+1,fr = n
      |                               ^~~
communication.cpp:115:44: warning: unused variable 'csta' [-Wunused-variable]
  115 |     long long 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:21: warning: 'frp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  106 |         if(cl == cr && fl == fr)
      |            ~~~~~~~~~^~~~~~~~~~~
communication.cpp:106:21: warning: 'flp' may be used uninitialized in this function [-Wmaybe-uninitialized]
communication.cpp:106:9: warning: 'crp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  106 |         if(cl == cr && fl == fr)
      |         ^~
communication.cpp:106:9: warning: 'clp' may be used uninitialized in this function [-Wmaybe-uninitialized]
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:176:21: warning: 'frp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  176 |         if(cl == cr && fl == fr)
      |            ~~~~~~~~~^~~~~~~~~~~
communication.cpp:182:8: warning: 'flp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  182 |     a2 = fl;
      |     ~~~^~~~
communication.cpp:176:9: warning: 'crp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  176 |         if(cl == cr && fl == fr)
      |         ^~
communication.cpp:181:8: warning: 'clp' may be used uninitialized in this function [-Wmaybe-uninitialized]
  181 |     a1 = cl;
      |     ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1804 KB Output is correct
2 Correct 10 ms 1832 KB Output is correct
3 Correct 12 ms 1836 KB Output is correct
4 Correct 8 ms 1872 KB Output is correct
5 Correct 8 ms 1744 KB Output is correct
6 Correct 19 ms 1944 KB Output is correct
7 Correct 27 ms 1696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 479 ms 1716 KB Output is partially correct
2 Partially correct 310 ms 1728 KB Output is partially correct
3 Partially correct 427 ms 1692 KB Output is partially correct
4 Partially correct 734 ms 1672 KB Output is partially correct
5 Partially correct 560 ms 1696 KB Output is partially correct
6 Partially correct 517 ms 1816 KB Output is partially correct
7 Partially correct 1752 ms 1880 KB Output is partially correct
8 Partially correct 2400 ms 1900 KB Output is partially correct
9 Partially correct 2184 ms 1904 KB Output is partially correct
10 Partially correct 1799 ms 1996 KB Output is partially correct
11 Partially correct 2166 ms 1824 KB Output is partially correct
12 Partially correct 2168 ms 2048 KB Output is partially correct
13 Partially correct 2228 ms 1904 KB Output is partially correct
14 Partially correct 1960 ms 1932 KB Output is partially correct
15 Correct 961 ms 1748 KB Output is correct
16 Correct 2379 ms 1808 KB Output is correct
17 Partially correct 690 ms 1800 KB Output is partially correct
18 Partially correct 553 ms 1816 KB Output is partially correct
19 Partially correct 724 ms 1836 KB Output is partially correct
20 Partially correct 654 ms 1840 KB Output is partially correct
21 Correct 627 ms 1788 KB Output is correct
22 Partially correct 622 ms 1832 KB Output is partially correct
23 Partially correct 874 ms 1752 KB Output is partially correct
24 Correct 8 ms 1780 KB Output is correct
25 Correct 6 ms 1692 KB Output is correct
26 Correct 12 ms 1748 KB Output is correct
27 Correct 7 ms 1764 KB Output is correct
28 Correct 8 ms 1696 KB Output is correct
29 Correct 20 ms 1904 KB Output is correct
30 Correct 42 ms 1700 KB Output is correct