답안 #860176

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
860176 2023-10-12T03:16:34 Z green_gold_dog Snake Escaping (JOI18_snake_escaping) C++17
5 / 100
2000 ms 60564 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;
 
constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;
 
random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());
 
template<typename T>
bool assign_max(T& a, T b) {
        if (b > a) {
                a = b;
                return true;
        }
        return false;
}
 
template<typename T>
bool assign_min(T& a, T b) {
        if (b < a) {
                a = b;
                return true;
        }
        return false;
}
 
template<typename T>
T square(T a) {
        return a * a;
}
 
template<>
struct std::hash<pair<ll, ll>> {
        ll operator() (pair<ll, ll> p) const {
                return ((__int128)p.first * MOD + p.second) % INF64;
        }
};
 
void solve() {
        ll l, q;
        cin >> l >> q;
        vector<ll> ans(q, 0);
        vector<ll> arr(1 << l, 0);
        for (ll i = 0; i < (1 << l); i++) {
                char c;
                cin >> c;
                arr[i] = c - '0';
        }
        vector<vector<ll>> all(1 << l);
        vector<ll> o1(q), o0(q);
        for (ll i = 0; i < q; i++) {
                string s;
                cin >> s;
                reverse(s.begin(), s.end());
                for (ll j = 0; j < l; j++) {
                        if (s[j] == '1') {
                                o1[i] += (1 << j);
                                o0[i] += (1 << j);
                        }
                        if (s[j] == '0') {
                                o1[i] += (1 << j);
                        }
                        if (s[j] == '?') {
                                o0[i] += (1 << j);
                        }
                }
                all[o1[i] & o0[i]].push_back(i);
        }
        for (ll i = 0; i < (1 << l); i++) {
                for (auto j : all[i]) {
                        ans[j] += arr[i];
                        if ((1 << l) - 1 != (i | o1[j])) {
                                all[(((i | o1[j]) + 1) | o1[j]) & o0[j]].push_back(j);
                        }
                }
                all[i].clear();
          		all[i].shrink_to_fit();
        }
        for (auto i : ans) {
                cout << i << '\n';
        }
}
 
int main() {
        if (IS_FILE) {
                freopen("", "r", stdin);
                freopen("", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t = 1;
        if (IS_TEST_CASES) {
                cin >> t;
        }
        for (ll i = 0; i < t; i++) {
                solve();
        }
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:97:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |                 freopen("", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~
snake_escaping.cpp:98:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |                 freopen("", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 548 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 548 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1581 ms 60564 KB Output is correct
12 Execution timed out 2041 ms 53476 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 548 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1581 ms 60564 KB Output is correct
12 Execution timed out 2041 ms 53476 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 548 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 724 ms 39048 KB Output is correct
12 Correct 1868 ms 37964 KB Output is correct
13 Correct 120 ms 37716 KB Output is correct
14 Correct 242 ms 37720 KB Output is correct
15 Execution timed out 2075 ms 37352 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 472 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 548 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1581 ms 60564 KB Output is correct
12 Execution timed out 2041 ms 53476 KB Time limit exceeded
13 Halted 0 ms 0 KB -