Submission #909381

#TimeUsernameProblemLanguageResultExecution timeMemory
909381green_gold_dogFurniture (JOI20_furniture)C++17
0 / 100
1 ms348 KiB
//#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 check(ll a, ll b, vector<vector<ll>>& arr, vector<ll>& col, bool d = true) { if (arr[a][b] && d) { return; } if ((a == 0 && b == 0) || (a == arr.size() - 1 && b == arr[0].size() - 1)) { return; } if (arr[a][b] || ((a == 0 || arr[a - 1][b]) && (b == 0 || arr[a][b - 1])) || ((a == arr.size() - 1 || arr[a + 1][b]) && (b == arr[0].size() - 1 || arr[a][b + 1]))) { if (arr[a][b] == 0) { col[a]--; } arr[a][b] = 1; if (a != 0) { check(a - 1, b, arr, col); } if (b != 0) { check(a, b - 1, arr, col); } if (a != arr.size() - 1) { check(a + 1, b, arr, col); } if (a != arr[0].size() - 1) { check(a, b + 1, arr, col); } } } void solve() { ll n, m; cin >> n >> m; vector<vector<ll>> arr(n, vector<ll>(m)); vector<ll> col(n, 0); for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { cin >> arr[i][j]; col[i] += arr[i][j] == 0; } } for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { check(i, j, arr, col); } } ll q; cin >> q; for (ll i = 0; i < q; i++) { ll x, y; cin >> x >> y; x--; y--; ll c = 1; if (arr[x][y] == 1) { cout << 1 << '\n'; continue; } ll ny = y - 1; while (ny >= 0) { if (arr[x][ny] || (x != n - 1 && arr[x + 1][ny] == 0)) { break; } c++; ny--; } ny = y + 1; while (ny < m) { if (arr[x][ny] || (x != 0 && arr[x - 1][ny] == 0)) { break; } c++; ny++; } if (c == col[x]) { cout << 0 << '\n'; continue; } cout << 1 << '\n'; arr[x][y] = 1; col[x]--; check(x, y, arr, col, false); } } 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 (stderr)

furniture.cpp: In function 'void check(ll, ll, std::vector<std::vector<long long int> >&, std::vector<long long int>&, bool)':
furniture.cpp:54:38: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if ((a == 0 && b == 0) || (a == arr.size() - 1 && b == arr[0].size() - 1)) {
      |                                    ~~^~~~~~~~~~~~~~~~~
furniture.cpp:54:61: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if ((a == 0 && b == 0) || (a == arr.size() - 1 && b == arr[0].size() - 1)) {
      |                                                           ~~^~~~~~~~~~~~~~~~~~~~
furniture.cpp:57:90: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         if (arr[a][b] || ((a == 0 || arr[a - 1][b]) && (b == 0 || arr[a][b - 1])) || ((a == arr.size() - 1 || arr[a + 1][b]) && (b == arr[0].size() - 1 || arr[a][b + 1]))) {
      |                                                                                        ~~^~~~~~~~~~~~~~~~~
furniture.cpp:57:132: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         if (arr[a][b] || ((a == 0 || arr[a - 1][b]) && (b == 0 || arr[a][b - 1])) || ((a == arr.size() - 1 || arr[a + 1][b]) && (b == arr[0].size() - 1 || arr[a][b + 1]))) {
      |                                                                                                                                  ~~^~~~~~~~~~~~~~~~~~~~
furniture.cpp:68:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |                 if (a != arr.size() - 1) {
      |                     ~~^~~~~~~~~~~~~~~~~
furniture.cpp:71:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |                 if (a != arr[0].size() - 1) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~
furniture.cpp: In function 'int main()':
furniture.cpp:134:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  134 |                 freopen("", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~
furniture.cpp:135:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |                 freopen("", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...