Submission #993933

#TimeUsernameProblemLanguageResultExecution timeMemory
993933MarwenElarbiFlight to the Ford (BOI22_communication)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include<vector> #include<cstdio> #include<set> #include<cstdlib> #include<cstdarg> #include<cassert> #include"communication.h" using namespace std; #define fi first #define se second #define ll long long #define pb push_back const int nax=2e5+5; /*void __attribute__((noreturn)) __attribute__((format(printf, 1, 2))) result(const char *msg, ...) { va_list args; va_start(args, msg); vfprintf(stdout, msg, args); fprintf(stdout, "\n"); va_end(args); exit(0); } namespace { enum { ENCODE, DECODE } current_phase; int N, X; vector<int> signals; size_t cursor = 0; bool flipped = false; } int send(int s) { if(current_phase == DECODE or (s != 0 and s != 1)) result("Invalid send."); printf("send(%d) -> ", s); fflush(stdout); int answer; if(scanf("%d", &answer) != 1 or (answer != 0 and answer != 1)) result("Invalid reply to send."); bool flipped_now = (s != answer); if(flipped and flipped_now) result("Invalid reply to send"); flipped = flipped_now; signals.push_back(answer); if(signals.size() > (size_t) 250) result("Looks (and smells) fishy."); return signals.back(); } int receive() { if(current_phase == ENCODE) result("Invalid receive."); if(cursor >= signals.size()) result("Assistant waiting for Godot."); int r = signals[cursor++]; printf("receive() -> %d\n", r); return r; }*/ void encode(int N, int X){ vector<pair<int,int>> v; v.pb({1,N}); int a[4]={0,6,9,15}; while(true){ int value=0; for(auto j:v) value+=j.se-j.fi+1; if(value<=2) return; int sz[4]={value/4,value/4,value/4,value-3*(value/4)}; vector<pair<int,int>> tab[4]; for(int i=0;i<4;i++){ int sum=0; for(int j=0;j<v.size();j++){ sum+=v[j].se-v[j].fi+1; if(sum>=sz[i]){ int diff=sum-sz[i]; tab[i].pb({v[j].fi,v[j].se-diff}); v[j].fi=v[j].se-diff+1; break; }else if(v[j].fi<=v[j].se){ tab[i].pb({v[j].fi,v[j].se}); v[j].fi=0; v[j].se=-1; } } } v.clear(); int ans; for(int i=0;i<4;i++){ bool test=false; for(auto j:tab[i]){ if(j.fi<=X&&X<=j.se) test=true; } if(test){ ans=i; break; } } vector<int> cur; for(int i=0;i<4;i++){ if(a[i]&(1<<i)) cur+=((send(1)&1)<<i); else cur+=((send(0)&1)<<i); } for(int i=0;i<4;i++){ int nab=cur^a[i]; bool bits[4]; for (int j = 0; j < 4; ++j) { bits[j]=( (nab&(1<<j)) ? 1 : 0 ) } bool test=false; for (int j = 0; j < 3; ++j) { test|=(bits[j]==bits[j+1]&&bits[j]==1); } if(test) continue; if(cur[i]==1){ for(auto j:tab[i]){ v.pb(j); } } } } } std::pair<int, int> decode(int N){ /*vector<vector<string>> tab(4 , vector<string>(8)); tab[0]={"0000","0001","0010","0100","0101","1000","1001","1010"}; // 0000 tab[1]={"0000","0001","0011","1000","1001","1011","1100","1101"}; // 1001 tab[2]={"0010","0011","0100","0110","0111","1100","1110","1111"}; // 0110 tab[3]={"0101","0110","0111","1010","1011","1101","1110","1111"}; // 1111 set<string> st; for(int i=0;i<4;i++) for(auto u:tab[i]) st.insert(u);*/ vector<pair<int,int>> v; v.pb({1,N}); int a[4]={0,6,9,15}; while(true){ int value=0; for(auto j:v) value+=j.se-j.fi+1; if(value<=2){ if(v.size()==2) return {v[0].fi,v[1].fi}; else return {v[0].fi,v[0].se}; } int sz[4]={value/4,value/4,value/4,value-3*(value/4)}; vector<pair<int,int>> tab[4]; for(int i=0;i<4;i++){ int sum=0; for(int j=0;j<v.size();j++){ sum+=v[j].se-v[j].fi+1; if(sum>=sz[i]){ int diff=sum-sz[i]; tab[i].pb({v[j].fi,v[j].se-diff}); v[j].fi=v[j].se-diff+1; break; }else if(v[j].fi<=v[j].se){ tab[i].pb({v[j].fi,v[j].se}); v[j].fi=0; v[j].se=-1; } } } v.clear(); vector<int> cur; for(int i=0;i<4;i++){ cur.pb(receive()); } for(int i=0;i<4;i++){ if(cur[i]){ for(auto j:tab[i]){ v.pb(j); } } } } } /*int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif if(scanf("%d %d", &N, &X) != 2 or X < 1 or X > N) result("Invalid input."); current_phase = ENCODE; encode(N, X); current_phase = DECODE; auto r = decode(N); if(r.first < 1 or r.first > N or r.second < 1 or r.second > N) result("Invalid answer."); if(r.first == X or r.second == X) result("Correct: %d signals sent.", (int) signals.size()); else result("Wrong answer."); }*/

Compilation message (stderr)

communication.cpp: In function 'void encode(int, int)':
communication.cpp:79:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             for(int j=0;j<v.size();j++){
      |                         ~^~~~~~~~~
communication.cpp:107:32: error: no match for 'operator+=' (operand types are 'std::vector<int>' and 'int')
  107 |             if(a[i]&(1<<i)) cur+=((send(1)&1)<<i);
      |                             ~~~^~~~~~~~~~~~~~~~~~
communication.cpp:108:22: error: no match for 'operator+=' (operand types are 'std::vector<int>' and 'int')
  108 |             else  cur+=((send(0)&1)<<i);
      |                   ~~~^~~~~~~~~~~~~~~~~~
communication.cpp:111:24: error: no match for 'operator^' (operand types are 'std::vector<int>' and 'int')
  111 |             int nab=cur^a[i];
      |                     ~~~^~~~~
      |                     |      |
      |                     |      int
      |                     std::vector<int>
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:45,
                 from communication.cpp:1:
/usr/include/c++/10/cstddef:142:3: note: candidate: 'constexpr std::byte std::operator^(std::byte, std::byte)'
  142 |   operator^(byte __l, byte __r) noexcept
      |   ^~~~~~~~
/usr/include/c++/10/cstddef:142:18: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::byte'
  142 |   operator^(byte __l, byte __r) noexcept
      |             ~~~~~^~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from communication.cpp:1:
/usr/include/c++/10/bits/ios_base.h:91:3: note: candidate: 'constexpr std::_Ios_Fmtflags std::operator^(std::_Ios_Fmtflags, std::_Ios_Fmtflags)'
   91 |   operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
      |   ^~~~~~~~
/usr/include/c++/10/bits/ios_base.h:91:27: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::_Ios_Fmtflags'
   91 |   operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
      |             ~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/ios_base.h:133:3: note: candidate: 'constexpr std::_Ios_Openmode std::operator^(std::_Ios_Openmode, std::_Ios_Openmode)'
  133 |   operator^(_Ios_Openmode __a, _Ios_Openmode __b)
      |   ^~~~~~~~
/usr/include/c++/10/bits/ios_base.h:133:27: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::_Ios_Openmode'
  133 |   operator^(_Ios_Openmode __a, _Ios_Openmode __b)
      |             ~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/ios_base.h:173:3: note: candidate: 'constexpr std::_Ios_Iostate std::operator^(std::_Ios_Iostate, std::_Ios_Iostate)'
  173 |   operator^(_Ios_Iostate __a, _Ios_Iostate __b)
      |   ^~~~~~~~
/usr/include/c++/10/bits/ios_base.h:173:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::_Ios_Iostate'
  173 |   operator^(_Ios_Iostate __a, _Ios_Iostate __b)
      |             ~~~~~~~~~~~~~^~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:66,
                 from communication.cpp:1:
/usr/include/c++/10/bitset:1453:5: note: candidate: 'template<long unsigned int _Nb> std::bitset<_Nb> std::operator^(const std::bitset<_Nb>&, const std::bitset<_Nb>&)'
 1453 |     operator^(const bitset<_Nb>& __x, const bitset<_Nb>& __y) _GLIBCXX_NOEXCEPT
      |     ^~~~~~~~
/usr/include/c++/10/bitset:1453:5: note:   template argument deduction/substitution failed:
communication.cpp:111:28: note:   'std::vector<int>' is not derived from 'const std::bitset<_Nb>'
  111 |             int nab=cur^a[i];
      |                            ^
In file included from /usr/include/c++/10/valarray:603,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from communication.cpp:1:
/usr/include/c++/10/bits/valarray_after.h:410:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__bitwise_xor, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__bitwise_xor, typename _Dom1::value_type>::result_type> std::operator^(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const std::_Expr<_Dom2, typename _Dom2::value_type>&)'
  410 |     _DEFINE_EXPR_BINARY_OPERATOR(^, __bitwise_xor)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/valarray_after.h:410:5: note:   template argument deduction/substitution failed:
communication.cpp:111:28: note:   'std::vector<int>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  111 |             int nab=cur^a[i];
      |                            ^
In file included from /usr/include/c++/10/valarray:603,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from communication.cpp:1:
/usr/include/c++/10/bits/valarray_after.h:410:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_xor, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__bitwise_xor, typename _Dom1::value_type>::result_type> std::operator^(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  410 |     _DEFINE_EXPR_BINARY_OPERATOR(^, __bitwise_xor)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/valarray_after.h:410:5: note:   template argument deduction/substitution failed:
communication.cpp:111:28: note:   'std::vector<int>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  111 |             int nab=cur^a[i];
      |                            ^
In file included from /usr/include/c++/10/valarray:603,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from communication.cpp:1:
/usr/include/c++/10/bits/valarray_after.h:410:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_xor, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__bitwise_xor, typename _Dom1::value_type>::result_type> std::operator^(const typename _Dom::value_type&, const std::_Expr<_Dom1, typename _Dom1::value_type>&)'
  410 |     _DEFINE_EXPR_BINARY_OPERATOR(^, __bitwise_xor)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/valarray_after.h:410:5: note:   template argument deduction/substitution failed:
communication.cpp:111:28: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'int'
  111 |             int nab=cur^a[i];
      |                            ^
In file included from /usr/include/c++/10/valarray:603,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from communication.cpp:1:
/usr/include/c++/10/bits/valarray_after.h:410:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_xor, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__bitwise_xor, typename _Dom1::value_type>::result_type> std::operator^(const std::_Expr<_Dom1, typename _Dom1::value_type>&, const std::valarray<typename _Dom::value_type>&)'
  410 |     _DEFINE_EXPR_BINARY_OPERATOR(^, __bitwise_xor)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/valarray_after.h:410:5: note:   template argument deduction/substitution failed:
communication.cpp:111:28: note:   'std::vector<int>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
  111 |             int nab=cur^a[i];
      |                            ^
In file included from /usr/include/c++/10/valarray:603,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from communication.cpp:1:
/usr/include/c++/10/bits/valarray_after.h:410:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_xor, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__bitwise_xor, typename _Dom1::value_type>::result_type> std::operator^(const std::valarray<typename _Dom::value_type>&, const std::_Expr<_Dom1, typename _Dom1::value_type>&)'
  410 |     _DEFINE_EXPR_BINARY_OPERATOR(^, __bitwise_xor)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/valarray_after.h:410:5: note:   template argument deduction/substitution failed:
communication.cpp:111:28: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'int'
  111 |             int nab=cur^a[i];
      |                            ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from communication.cpp:1:
/usr/include/c++/10/valarray:1190:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__bitwise_xor, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__bitwise_xor, _Tp>::result_type> std::operator^(const std::valarray<_Tp>&, const std::valarray<_Tp>&)'
 1190 | _DEFINE_BINARY_OPERATOR(^, __bitwise_xor)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/valarray:1190:1: note:   template argument deduction/substitution failed:
communication.cpp:111:28: note:   'std::vector<int>' is not derived from 'const std::valarray<_Tp>'
  111 |             int nab=cur^a[i];
      |                            ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from communication.cpp:1:
/usr/include/c++/10/valarray:1190:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__bitwise_xor, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__bitwise_xor, _Tp>::result_type> std::operator^(const std::valarray<_Tp>&, const typename std::valarray<_Tp>::value_type&)'
 1190 | _DEFINE_BINARY_OPERATOR(^, __bitwise_xor)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/valarray:1190:1: note:   template argument deduction/substitution failed:
communication.cpp:111:28: note:   'std::vector<int>' is not derived from 'const std::valarray<_Tp>'
  111 |             int nab=cur^a[i];
      |                            ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from communication.cpp:1:
/usr/include/c++/10/valarray:1190:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__bitwise_xor, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__bitwise_xor, _Tp>::result_type> std::operator^(const typename std::valarray<_Tp>::value_type&, const std::valarray<_Tp>&)'
 1190 | _DEFINE_BINARY_OPERATOR(^, __bitwise_xor)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/valarray:1190:1: note:   template argument deduction/substitution failed:
communication.cpp:111:28: note:   mismatched types 'const std::valarray<_Tp>' and 'int'
  111 |             int nab=cur^a[i];
      |                            ^
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:105,
                 from communication.cpp:1:
/usr/include/c++/10/future:155:20: note: candidate: 'constexpr std::launch std::operator^(std::launch, std::launch)'
  155 |   constexpr launch operator^(launch __x, launch __y)
      |                    ^~~~~~~~
/usr/include/c++/10/future:155:37: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::launch'
  155 |   constexpr launch operator^(launch __x, launch __y)
      |                              ~~~~~~~^~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:127,
                 from communication.cpp:1:
/usr/include/c++/10/charconv:672:3: note: candidate: 'constexpr std::chars_format std::operator^(std::chars_format, std::chars_format)'
  672 |   operator^(chars_format __lhs, chars_format __rhs) noexcept
      |   ^~~~~~~~
/usr/include/c++/10/charconv:672:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::chars_format'
  672 |   operator^(chars_format __lhs, chars_format __rhs) noexcept
      |             ~~~~~~~~~~~~~^~~~~
communication.cpp:115:49: error: expected ';' before '}' token
  115 |                 bits[j]=( (nab&(1<<j)) ? 1 : 0 )
      |                                                 ^
      |                                                 ;
  116 |             }
      |             ~                                    
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:155:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  155 |             for(int j=0;j<v.size();j++){
      |                         ~^~~~~~~~~
communication.cpp:143:9: warning: unused variable 'a' [-Wunused-variable]
  143 |     int a[4]={0,6,9,15};
      |         ^