Submission #824015

#TimeUsernameProblemLanguageResultExecution timeMemory
824015AmylopectinFlight to the Ford (BOI22_communication)C++17
74 / 100
2400 ms2048 KiB
#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 (stderr)

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;
      |     ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...