Submission #55968

#TimeUsernameProblemLanguageResultExecution timeMemory
55968youngyojunSandwich (JOI16_sandwich)C++11
100 / 100
4126 ms16856 KiB
#include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define sz(V) ((int)(V).size()) #define allv(V) ((V).begin()),((V).end()) #define befv(V) ((V)[(sz(V)-2)]) #define sorv(V) sort(allv(V)) #define revv(V) reverse(allv(V)) #define univ(V) (V).erase(unique(allv(V)),(V).end()) #define clv(V) (V).clear() #define upmin(a,b) (a)=min((a),(b)) #define upmax(a,b) (a)=max((a),(b)) #define INF (0x3f3f3f3f) #define INFLL (0x3f3f3f3f3f3f3f3fll) using namespace std; typedef long long ll; const int MAXH = 405; const int MAXW = 405; int dp[2][MAXH][MAXW]; bitset<(MAXH<<12)> chk, isp; int CNT; char A[MAXH][MAXW]; int H, W; int g(char c, int dr) { if('N' == c) return !!(dr < 2); if('Z' == c) return !!(dr && dr < 3); return 0; } void f(int t, int y, int x) { if(chk[(y<<10)+x]) return; chk[(y<<10)+x] = true; CNT++; int ax = (t ? x+1 : x-1), by = ((!!t == ('N' == A[y][x])) ? y-1 : y+1); int at = !g(A[y][ax], x < ax ? 3 : 1), bt = !g(A[by][x], y < by ? 0 : 2); f(at, y, ax); f(bt, by, x); isp[(y<<10)+x] = (isp[(y<<10)+ax] && isp[(by<<10)+x]); } void init() { chk.reset(); isp.reset(); for(int i = 0; i <= H+1; i++) chk[i<<10] = chk[(i<<10)+W+1] = isp[i<<10] = isp[(i<<10)+W+1] = true; for(int i = 0; i <= W+1; i++) chk[i] = chk[((H+1)<<10)+i] = isp[i] = isp[((H+1)<<10)+i] = true; CNT = 0; } int main() { scanf("%d%d", &H, &W); for(int i = 1; i <= H; i++) scanf(" %s", A[i]+1); for(int y = 1; y <= H; y++) { init(); for(int x = 1; x <= W; x++) { f(0, y, x); dp[0][y][x] = isp[(y<<10)+x] ? CNT : INF; } init(); for(int x = W; x; x--) { f(1, y, x); dp[1][y][x] = isp[(y<<10)+x] ? CNT : INF; } } for(int i = 1; i <= H; i++) { for(int j = 1; j <= W; j++) { int t = min(dp[0][i][j], dp[1][i][j]); printf("%d ", INF <= t ? -1 : t*2); } puts(""); } return 0; }

Compilation message (stderr)

sandwich.cpp: In function 'int main()':
sandwich.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &H, &W);
  ~~~~~^~~~~~~~~~~~~~~~
sandwich.cpp:58:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= H; i++) scanf(" %s", A[i]+1);
                              ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...