Submission #1129875

#TimeUsernameProblemLanguageResultExecution timeMemory
1129875agrim_09Snake Escaping (JOI18_snake_escaping)C++20
5 / 100
2093 ms14472 KiB
// #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define endl '\n'; #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define py cout << "YES" << endl; #define pn cout << "NO" << endl; #define pb push_back #define int long long typedef long double lld; #define double lld typedef long long ll; typedef unsigned long long ull; const ll inf = 1e18; const ll mod = 1e9+7; const int N = 2e5; vector<int>primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; // Check for queue, priorioty_queue, stack, ordered_set solutions // stack => LIFO (whatever goes in last comes out last) // queue => FIFO (whatever goes in first comes out first) // priority_queue => Dynamic queries of minimum/maximum // ordered_set => set in vector form //[order_of_key(k) gives number of elements less than k, while find_by_order(i) gives i^th element] // To comment multiple lines : ctrl + / // To find and replace : ctrl+H void judge(){ srand(time(NULL)); #ifndef ONLINE_JUDGE freopen("inputC.txt","r",stdin); freopen("outputC.txt","w",stdout); freopen("Error.txt", "w", stderr); #define debug(x...) cerr << #x <<" = "; _print(x); cerr << endl; #else #define debug(x...) #endif } void usaco(string s) { freopen((s + ".in").c_str(),"r",stdin); freopen((s + ".out").c_str(),"w",stdout); } struct node{ // Make changes here int sum; node(int x = 0){ sum = x; } }; class SegTree{ #define lc x+1 #define rc 2*(mid-start+1) + x #define mid (start+end)/2 int n; vector<node>t; vector<int>a; node unite(node a, node b){ return node(a.sum+b.sum); } private: void build(int x, int start, int end){ if(start==end){ t[x] = node(a[start]); return; } build(lc,start,mid); build(rc,mid+1,end); t[x] = unite(t[lc],t[rc]); return; } void update(int x, int start, int end, int idx, int val){ if(start==end){ t[x] = node(val); return; } if(idx<=mid){ update(lc,start,mid,idx,val); } else{ update(rc,mid+1,end,idx,val); } t[x] = unite(t[lc],t[rc]); return; } node query(int x, int start, int end, int l, int r){ if(l<=start and end<=r){ return t[x]; } if(r<=mid){ return query(lc,start,mid,l,r); } else if(mid<l){ return query(rc,mid+1,end,l,r); } else{ return unite(query(lc,start,mid,l,r),query(rc,mid+1,end,l,r)); } } public: SegTree(vector<int>& tmp){ n = tmp.size(); t.resize(2 * n); a = tmp; build(0, 0, n - 1); } node query(int l, int r){ return query(0, 0, n - 1, l, r); } void update(int pos, int val){ update(0, 0, n - 1, pos, val); } }; signed main(){ fastio; //judge(); int n,q; cin >> n >> q; n = (1<<n); vector<int>a(n); for(int i = 0;i<n;i++){ char c; cin >> c; a[i] = (c-'0'); } while(q--){ string s; cin >> s; reverse(s.begin(),s.end()); vector<int>nums = {0}; int curr = 0; for(int i = 0;i<s.size();i++){ if(s[i]=='?'){ vector<int>tmp; for(auto x : nums){ tmp.pb(x+(1<<i)); tmp.pb(x); } nums = tmp; } else{ int t= (s[i]-'0'); curr += t*(1<<i); } } int sum = 0; for(auto x : nums){ sum += a[x+curr]; } cout << sum << endl; } }

Compilation message (stderr)

snake_escaping.cpp: In function 'void judge()':
snake_escaping.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("inputC.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen("outputC.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     freopen("Error.txt", "w", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp: In function 'void usaco(std::string)':
snake_escaping.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     freopen((s + ".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen((s + ".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...