Submission #799740

#TimeUsernameProblemLanguageResultExecution timeMemory
799740BoomydayUnscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
2 ms476 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using ii = pair<int,int>; using pl = pair<ll,ll>; using pd = pair<db,db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<str>; using vii = vector<ii>; using vpl = vector<pl>; using vpd = vector<pd>; #define tcT template<class T #define tcTU tcT, class U tcT> using V = vector<T>; tcT, size_t SZ> using AR = array<T,SZ>; tcT> using PR = pair<T,T>; // pairs #define mp make_pair #define f first #define s second #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define len(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) rbegin(x), rend(x) #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define eb emplace_back #define pf push_front const int MOD = 1000000007; // 998244353; const int MX = 2e5+5; const ll INF = 1e18; // not too close to LLONG_MAX const ld PI = acos((ld)-1); const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!! #include <vector> #include <cstdio> #include <string> #include <set> #include <cstdlib> #include <iostream> #include "messy.h" using namespace std; // sz changes, dp doesn't vector<string> get_strs(int sz, int dp){ vector<string> ans; if (sz==dp){ string base(dp,'0'); F0R(i, dp/2){ base[i]='1'; ans.pb(base); base[i]='0'; } return ans; } vector<string> next_strs = get_strs(sz/2,dp); string blk(sz/2,'1'); trav(st, next_strs){ ans.pb(blk+st); ans.pb(st+blk); } return ans; } vector<int> perm; // the active ins are 1 if its not that node in the shuffled word // the range of nodes we are searching void solve(string active_in, int lb, int ub){ if (lb==ub){ int ind = find(all(active_in),'0')-active_in.begin(); perm[ind] = lb; return; } string yes = active_in, no = active_in; string chk = active_in; F0R(i, active_in.size()){ if (chk[i] == '1') continue; chk[i] = '1'; if (check_element(chk)) { no[i] = '1'; } else yes[i] = '1'; chk[i] = '0'; } int mid = (lb+ub)/2; solve(yes, lb, mid); solve(no, mid+1, ub); } std::vector<int> restore_permutation(int n, int w, int r) { perm.rsz(n); int depth = n; while (depth>1){ trav(st, get_strs(n, depth)){ add_element(st); } depth >>=1; } compile_set(); solve(string(n,'0'),0,n-1); return perm; }

Compilation message (stderr)

messy.cpp: In function 'void solve(std::string, int, int)':
messy.cpp:35:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                                        ^
messy.cpp:36:18: note: in expansion of macro 'FOR'
   36 | #define F0R(i,a) FOR(i,0,a)
      |                  ^~~
messy.cpp:115:5: note: in expansion of macro 'F0R'
  115 |     F0R(i, active_in.size()){
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...