結果
問題 | No.421 しろくろチョコレート |
ユーザー |
![]() |
提出日時 | 2023-01-10 21:36:38 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,215 bytes |
コンパイル時間 | 8,478 ms |
コンパイル使用メモリ | 292,996 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-21 12:20:06 |
合計ジャッジ時間 | 16,171 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 WA * 5 RE * 59 |
ソースコード
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <deque> #include <list> #include <unordered_map> #include <unordered_set> #include <iomanip> #include <set> #include <map> #include <ctime> #include <stack> #include <functional> #include <cstdio> #include <string> #include <iostream> #include <limits> #include <stdexcept> #include <numeric> #include <fstream> #include <chrono> #include <utility> #include <cassert> #include <random> #include <time.h> using namespace std; // /* #include <atcoder/all> using namespace atcoder; using mint =modint998244353; //using mint =modint1000000009; //using mint =modint1000000007; #define ip(x) is_prime_constexpr(x) istream &operator>>(istream &is, mint &a) { int v; cin >> v; a = v; return is; } ostream &operator<<(ostream &os, const mint &a) { return os << a.val(); } // */ template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } typedef long long ll; typedef unsigned long long ull; typedef long double LD; typedef double D; typedef pair<ll,ll> P; typedef map<ll,ll> M; void tatananonano() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout<< fixed << setprecision(10); } #define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;IN(__VA_ARGS__) template <class T> void scan(T &a) { cin >> a; } void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {scan(head);IN(tail...);} #define rep(i,n) for(ll i=0;i<n;i++) #define rrep(i,n) for(ll i=1;i<n;i++) #define jep(i, a, n)for (ll i =(ll)a; i<(ll)n;++i) #define drep2(i, m, n) for (int i = (n)-1; i >= (m); --i) #define drep(i, n) drep2(i,0,n) #define fore(i,a) for(const auto &i:a) #define all(x) (x).begin(),(x).end() #define pb push_back #define lb lower_bound #define ub upper_bound #define uni(x) sort(all(x));x.erase(unique(all(x)),x.end()) #define TFU(s) transform(all(s),begin(s),::toupper);//大文字にする #define TFL(s) transform(all(s),begin(s),::tolower);//小文字にする #define replace(s,a,A) replace(s,'a','A')//str(s)のaをAにする #define ROT(s,i) rotate(s.begin(),s.begin()+i,s.end())//sのi番目から後ろを前にする #define PQ priority_queue #define PQD PQ<P,vector<P>,greater<P>>//小さい順に吐く #define PQS PQ<ll,vec,greater<ll>>//小さい順に吐く #define fi first #define se second #define bit(n,k) ((n>>k)&1LL) #define printd(n,x) cout<<fixed<<setprecision(n)<<x<<endl #define cinv(a,n); rep(i,n){cin>>a[i];} #define popcount(n) __builtin_popcountll(n) template<class T> inline bool chmax(T& a,T b){if(a < b){a=b;return 1;}return 0;} template<class T> inline bool chmin(T& a,T b){if(a > b){a=b;return 1;}return 0;} typedef vector<ll> vec; typedef vector<vec> mat; //const ll mod = 1000000009; const ll mod = 998244353; //const ll mod = 1000000007; const auto INF = (1LL<<(60)); ll modpow(ll a,ll n,ll mod){if(mod==1)return 0;ll ret=1;ll p=a%mod;while(n){if(n&1)ret=ret*p%mod;p=p*p%mod;n>>=1;}return ret; } M factor(ll n) {M ret;for(ll i=2;i*i<=n;i++){while(n%i==0){ret[i]++;n /= i;}}if(n != 1){ret[n]=1;}return ret;}//素因数分解 vec divisor(ll n){vec K;for(ll i=1;i*i<=n;i++){if(n%i==0){K.pb(i);if(i*i!=n)K.pb(n/i);}}sort(all(K));return K;}//約数列挙 ll dx[4]={0,1,0,-1},dy[4]={-1,0,1,0}; int main(){ tatananonano(); LL(n,m); vector<string> s(n); rep(i,n){cin>>s[i];} vector<P> w,b; rep(i,n){ rep(j,m){ if(s[i][j]=='w'){w.pb({i,j});} if(s[i][j]=='b'){b.pb({i,j});} } } mf_graph<ll> mf(n*m+2); rep(i,w.size()){mf.add_edge(n*m,(w[i].fi*m)+w[i].se,1);} rep(i,b.size()){mf.add_edge((b[i].fi*m)+b[i].se,n*m+1,1);} rep(i,w.size()){ auto [u,v]=w[i]; rep(j,4){ if(0<=min(u+dx[j],v+dy[j]) and u+dx[i]<n and v+dy[j]<m)if(s[u+dx[j]][v+dy[j]]=='b'){ mf.add_edge(u*m+v,(u+dx[j])*m+(v+dy[j]),1); } } } auto key=mf.flow(n*m,n*m+1); auto mx=max(w.size(),b.size()); auto mn=min(w.size(),b.size()); cout<<(key*100)+(mn-key)*10+(mx-mn)<<'\n'; }