Submission #1210569

#TimeUsernameProblemLanguageResultExecution timeMemory
1210569btninhSelotejp (COCI20_selotejp)C++20
35 / 110
16 ms328 KiB
#include <bits/stdc++.h> using namespace std; #define btninh signed main #define int long long #define REP(i, n) for(int i = 0; i < n; ++i) #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define FORD(i, a, b) for(int i = a; i >= b; --i) #define fast ios::sync_with_stdio(0); cin.tie(0) #define IO(x) if(fopen(x".inp","r")){freopen(x".inp","r",stdin);freopen(x".out","w",stdout);} #define vi vector<int> #define vii vector<vector<int>> #define fi first #define se second #define pb push_back #define pii pair<int,int> template<class Typ> bool mini(Typ &x, Typ y){if (x > y) return x = y, true; return false;} template<class Typ> bool maxi(Typ &x, Typ y){if (x < y) return x = y, true; return false;} const int N = 1005; const int inf = 1e18; int n, m, dp[2][1 << 11]; char a[N][15]; int getBit(int m, int i){ return ((m >> i) & 1); } btninh(){ fast; IO("main"); cin >> n >> m; FOR(i, 1, n)FOR(j, 1, m)cin >> a[i][j]; memset(dp, 0x3f3f3f, sizeof dp); dp[0][0] = 0; int cur = 1, lst = 0; FOR(i, 1, n){ FOR(j, 1, m){ FOR(msk, 0, (1 << m) - 1){ if (a[i][j] == '.'){ mini(dp[cur][msk & ~(1<<(j-1))], dp[lst][msk]); } else{ if (getBit(msk, j - 1)) { mini(dp[cur][msk], dp[lst][msk]); mini(dp[cur][msk], dp[lst][msk ^ (1 <<(j-1))] + 1); } else{ mini(dp[cur][msk], dp[lst][msk]); mini(dp[cur][msk^(1<<(j-1))], dp[lst][msk] + 1); if (a[i][j] == '#' && (a[i][j - 1] == '.' || j == 1 || (j >= 2 && getBit(msk, j - 2)))) dp[cur][msk]++; } } } FOR(msk, 0, (1<<m) - 1) dp[lst][msk] = 0x3f3f3f; swap(cur, lst); } } int ans = 0x3f3f3f; FOR(msk, 0, (1<<m) - 1){ ans = min(ans, dp[lst][msk]); } cout<< ans; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:10:45: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | #define IO(x) if(fopen(x".inp","r")){freopen(x".inp","r",stdin);freopen(x".out","w",stdout);}
      |                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:31:5: note: in expansion of macro 'IO'
   31 |     IO("main");
      |     ^~
Main.cpp:10:72: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 | #define IO(x) if(fopen(x".inp","r")){freopen(x".inp","r",stdin);freopen(x".out","w",stdout);}
      |                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:31:5: note: in expansion of macro 'IO'
   31 |     IO("main");
      |     ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...