Submission #552239

# Submission time Handle Problem Language Result Execution time Memory
552239 2022-04-22T20:39:46 Z urosk Snake Escaping (JOI18_snake_escaping) C++14
Compilation error
0 ms 0 KB
// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x)
// __builtin_clz(x) vodece nule
// __builtin_clzll(x)
// __builtin_ctz(x) nule na pocetku
// __builtin_ctzll(x)
// 2000000011
// 2000000033
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) ((ll)(a.size()))
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pi 3.14159265358979323846
#define here cerr<<"=============================================================================\n"
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}}
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;

template<typename T> using vc = vector<T>;
template<typename T> using vvc = vc<vc<T>>;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}

void setIO(string inoutname)
{
	freopen((inoutname+".in").c_str(),"r",stdin);
    	freopen((inoutname+".out").c_str(),"w",stdout);
}
#define mod 1
ll gcd(ll a, ll b)
{
   if(b==0) return a;
   if(a==0) return b;
   if(a>=b)  return gcd(a%b,b);
   return  gcd(a,b%a);
}
ll lcm(ll a,ll b){
   return (a/gcd(a,b))*b;
}
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
	if(x==mod) x = 0;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
ll po(ll x,ll y){
    if(y==0) return 1LL;
    ll ans = po(x,y/2);
    ans = mul(ans,ans);
    if(y&1) ans = mul(ans,x);
    return ans;
}
ll inv(ll x){return po(x,mod-2);}
#define maxn 2000005
ll n,q;
ll l;
ll sub[maxn],sup[maxn],btc[maxn];
ll s[maxn];
void tc(){
	daj_mi_malo_vremena
    cin >> l >> q;
    n = (1<<l)-1;
    string ss; cin >> ss;
    for(ll i = 0;i<=n;i++) s[i] = (ss[i]-'0');
    for(ll i = 0;i<=n;i++){
        btc[i] = __builtin_popcountll(i);
        sub[i] = sup[i] = s[i];
    }
    for(ll j = 0;j<l;j++){
        for(ll i = 0;i<=n;i++){
            if(((1<<j)&i)==0){
                sup[i]+=sup[i^(1<<j)];
            }else{
                sub[i]+=sub[i^(1<<j)];
            }
        }
    }

    ceri(sub,0,n);
    ceri(btc,0,n);
    while(q--){
        string ss; getline(cin,s);
        ll a = 0,b = 0,c = 0;
        ll ca = 0,cb = 0,cc = 0;
        for(ll i = 0;i<l;i++){
            ll k = l-i-1;
            if(ss[i]=='0'){
                a|=(1<<k); ca++;
            }else if(ss[i]=='1'){
                b|=(1<<k); cb++;
            }else{
                c|=(1<<k); cc++;
            }
        }
        ll mc = min({ca,cb,cc});
        ll ans = 0;
        if(ca == mc){
            for(ll mask = a;mask!=0;mask=a&(mask-1)){
                ans+=(1-2*((btc[mask])&1))*sup[b|mask];
            }
            ans+=sup[b];
        }else if(cb==mc){
            for(ll mask = b;mask!=0;mask=b&(mask-1)){
                ans+=(1-2*((btc[mask])&1))*sub[c|(b^mask)];
            }
            ans += sub[c|b];
        }else{
            for(ll mask = c;mask!=0;mask=c&(mask-1)){
                ans+=s[b|mask];
            }
            ans+=s[b];
        }
        cout<<ans<<endl;
    }
}
int main(){
	daj_mi_malo_vremena
	//setIO("lol");
	int t; t = 1;
	while(t--){
		tc();
	}
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'void tc()':
snake_escaping.cpp:116:33: error: no matching function for call to 'getline(std::istream&, int [2000005])'
  116 |         string ss; getline(cin,s);
      |                                 ^
In file included from /usr/include/stdio.h:864,
                 from /usr/include/c++/10/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:46,
                 from snake_escaping.cpp:9:
/usr/include/x86_64-linux-gnu/bits/stdio.h:118:1: note: candidate: '__ssize_t getline(char**, size_t*, FILE*)'
  118 | getline (char **__lineptr, size_t *__n, FILE *__stream)
      | ^~~~~~~
/usr/include/x86_64-linux-gnu/bits/stdio.h:118:1: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/10/string:56,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 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 snake_escaping.cpp:9:
/usr/include/c++/10/bits/basic_string.tcc:1548:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, _CharT)'
 1548 |     getline(basic_istream<_CharT, _Traits>& __in,
      |     ^~~~~~~
/usr/include/c++/10/bits/basic_string.tcc:1548:5: note:   template argument deduction/substitution failed:
snake_escaping.cpp:116:33: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'int [2000005]'
  116 |         string ss; getline(cin,s);
      |                                 ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 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 snake_escaping.cpp:9:
/usr/include/c++/10/bits/basic_string.h:6498:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 6498 |     getline(basic_istream<_CharT, _Traits>& __is,
      |     ^~~~~~~
/usr/include/c++/10/bits/basic_string.h:6498:5: note:   template argument deduction/substitution failed:
snake_escaping.cpp:116:33: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'int [2000005]'
  116 |         string ss; getline(cin,s);
      |                                 ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 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 snake_escaping.cpp:9:
/usr/include/c++/10/bits/basic_string.h:6506:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, _CharT)'
 6506 |     getline(basic_istream<_CharT, _Traits>&& __is,
      |     ^~~~~~~
/usr/include/c++/10/bits/basic_string.h:6506:5: note:   template argument deduction/substitution failed:
snake_escaping.cpp:116:33: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'int [2000005]'
  116 |         string ss; getline(cin,s);
      |                                 ^
In file included from /usr/include/c++/10/string:55,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 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 snake_escaping.cpp:9:
/usr/include/c++/10/bits/basic_string.h:6513:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)'
 6513 |     getline(basic_istream<_CharT, _Traits>&& __is,
      |     ^~~~~~~
/usr/include/c++/10/bits/basic_string.h:6513:5: note:   template argument deduction/substitution failed:
snake_escaping.cpp:116:33: note:   mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>' and 'int [2000005]'
  116 |         string ss; getline(cin,s);
      |                                 ^
snake_escaping.cpp: In function 'void setIO(std::string)':
snake_escaping.cpp:50:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:51:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~