답안 #605682

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605682 2022-07-25T22:27:06 Z duality Flight to the Ford (BOI22_communication) C++17
74 / 100
3434 ms 1964 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#include "communication.h"

void encode(int N,int X) {
    int i,j;
    vi vv = {0,6,9,15};
    vpii poss;
    poss.pb(mp(1,N));
    while (1) {
        int l = 0;
        for (i = 0; i < poss.size(); i++) l += poss[i].second-poss[i].first+1;
        if (l <= 2) return;
        sort(poss.begin(),poss.end());
        int num = 0;
        for (i = 0; i < poss.size(); i++) {
            if (X >= poss[i].second) num += poss[i].second-poss[i].first+1;
            else if (X >= poss[i].first) num += X-poss[i].first+1;
        }
        int s = (l+3)/4,q = (num-1)/s;
        int S = vv[q],T = 0;
        for (i = 0; i < 4; i++) T |= send((S >> i) & 1) << i;
        vi cand;
        for (i = 0; i < 4; i++) {
            for (j = 1; j < 4; j++) {
                if (((vv[i]^T) & (1 << j)) && ((vv[i]^T) & (1 << (j-1)))) break;
            }
            if (j == 4) cand.pb(i);
        }
        vpii poss2;
        for (int c: cand) {
            int x = 0;
            for (i = 0; i < poss.size(); i++) {
                int l = max(x+1,c*s+1),r = min(x+poss[i].second-poss[i].first+1,(c+1)*s);
                if (l <= r) poss2.pb(mp(poss[i].first+l-(x+1),poss[i].first+r-(x+1)));
                x += poss[i].second-poss[i].first+1;
            }
        }
        poss = poss2;
    }
}
pair<int,int> decode(int N) {
    int i,j;
    vi vv = {0,6,9,15};
    vpii poss;
    poss.pb(mp(1,N));
    while (1) {
        int l = 0;
        for (i = 0; i < poss.size(); i++) l += poss[i].second-poss[i].first+1;
        if (l <= 2) {
            vi all;
            for (i = 0; i < poss.size(); i++) {
                for (j = poss[i].first; j <= poss[i].second; j++) all.pb(j);
            }
            if (all.size() == 1) return mp(all[0],all[0]);
            else return mp(all[0],all[1]);
        }
        sort(poss.begin(),poss.end());
        int s = (l+3)/4,T = 0;
        for (i = 0; i < 4; i++) T |= (receive() << i);
        vi cand;
        for (i = 0; i < 4; i++) {
            for (j = 1; j < 4; j++) {
                if (((vv[i]^T) & (1 << j)) && ((vv[i]^T) & (1 << (j-1)))) break;
            }
            if (j == 4) cand.pb(i);
        }
        vpii poss2;
        for (int c: cand) {
            int x = 0;
            for (i = 0; i < poss.size(); i++) {
                int l = max(x+1,c*s+1),r = min(x+poss[i].second-poss[i].first+1,(c+1)*s);
                if (l <= r) poss2.pb(mp(poss[i].first+l-(x+1),poss[i].first+r-(x+1)));
                x += poss[i].second-poss[i].first+1;
            }
        }
        poss = poss2;
    }
}

Compilation message

communication.cpp: In function 'void encode(int, int)':
communication.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (i = 0; i < poss.size(); i++) l += poss[i].second-poss[i].first+1;
      |                     ~~^~~~~~~~~~~~~
communication.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for (i = 0; i < poss.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
communication.cpp:87:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |             for (i = 0; i < poss.size(); i++) {
      |                         ~~^~~~~~~~~~~~~
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:103:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |         for (i = 0; i < poss.size(); i++) l += poss[i].second-poss[i].first+1;
      |                     ~~^~~~~~~~~~~~~
communication.cpp:106:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |             for (i = 0; i < poss.size(); i++) {
      |                         ~~^~~~~~~~~~~~~
communication.cpp:125:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |             for (i = 0; i < poss.size(); i++) {
      |                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1656 KB Output is correct
2 Correct 12 ms 1620 KB Output is correct
3 Correct 17 ms 1772 KB Output is correct
4 Correct 12 ms 1756 KB Output is correct
5 Correct 11 ms 1752 KB Output is correct
6 Correct 23 ms 1872 KB Output is correct
7 Correct 43 ms 1752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 767 ms 1724 KB Output is partially correct
2 Partially correct 387 ms 1732 KB Output is partially correct
3 Partially correct 418 ms 1660 KB Output is partially correct
4 Partially correct 895 ms 1664 KB Output is partially correct
5 Partially correct 818 ms 1660 KB Output is partially correct
6 Partially correct 524 ms 1720 KB Output is partially correct
7 Partially correct 2135 ms 1736 KB Output is partially correct
8 Partially correct 3328 ms 1940 KB Output is partially correct
9 Partially correct 3223 ms 1876 KB Output is partially correct
10 Partially correct 3034 ms 1888 KB Output is partially correct
11 Partially correct 3316 ms 1932 KB Output is partially correct
12 Partially correct 2771 ms 1884 KB Output is partially correct
13 Partially correct 3116 ms 1964 KB Output is partially correct
14 Partially correct 2906 ms 1900 KB Output is partially correct
15 Partially correct 1670 ms 1748 KB Output is partially correct
16 Partially correct 3434 ms 1744 KB Output is partially correct
17 Partially correct 765 ms 1764 KB Output is partially correct
18 Partially correct 870 ms 1796 KB Output is partially correct
19 Partially correct 786 ms 1836 KB Output is partially correct
20 Partially correct 821 ms 1744 KB Output is partially correct
21 Partially correct 1004 ms 1812 KB Output is partially correct
22 Partially correct 1083 ms 1828 KB Output is partially correct
23 Partially correct 1466 ms 1860 KB Output is partially correct
24 Correct 6 ms 1684 KB Output is correct
25 Correct 12 ms 1684 KB Output is correct
26 Correct 11 ms 1760 KB Output is correct
27 Correct 6 ms 1776 KB Output is correct
28 Correct 13 ms 1740 KB Output is correct
29 Correct 28 ms 1876 KB Output is correct
30 Correct 44 ms 1664 KB Output is correct