Submission #258104

#TimeUsernameProblemLanguageResultExecution timeMemory
258104sjimedSandwich (JOI16_sandwich)C++14
35 / 100
8041 ms9720 KiB
#include<bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(false); cin.tie(NULL) #define fi first #define se second #define pb push_back #define eb emplace_back #define em emplace #define all(v) (v).begin(), (v).end() #define pre(a) cout<<fixed; cout.precision(a) #define mp make_pair typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int inf = 1e9; const ll INF = 1e18; int n, m; string s[444]; int chk[444][444]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int t[2][2][2] = { 1, 2, 0, 3, 2, 3, 0, 1 }; int dir[2][4] = { 1, 0, 0, 1, 1, 1, 0, 0 }; int dfs(int x, int y, int d) { if(chk[x][y] == 1) return inf; if(chk[x][y] == 2) return 0; //cout << x << "!!! " << y << " " << d << endl; chk[x][y]=1; int ret = 2; for(int i=0; i<2; i++) { int nx = x + dx[t[s[x][y]][d][i]]; int ny = y + dy[t[s[x][y]][d][i]]; if(nx < 0 || nx >= n || ny < 0 || ny >= m) continue; ret += dfs(nx, ny, dir[s[nx][ny]][t[s[x][y]][d][i]]); ret = min(inf, ret); } chk[x][y]=2; return ret; } int main() { fast; cin >> n >> m; for(int i=0; i<n; i++) { cin >> s[i]; for(int j=0; j<m; j++) { if(s[i][j] == 'N') s[i][j] = 0; else s[i][j] = 1; } } for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { memset(chk, 0, sizeof(chk)); int ans = dfs(i, j, 0); memset(chk, 0, sizeof(chk)); ans = min(ans, dfs(i, j, 1)); if(ans == inf) cout << -1 << " "; else cout << ans << " "; } cout << endl; } }

Compilation message (stderr)

sandwich.cpp: In function 'int dfs(int, int, int)':
sandwich.cpp:51:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   int nx = x + dx[t[s[x][y]][d][i]];
                            ^
sandwich.cpp:52:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   int ny = y + dy[t[s[x][y]][d][i]];
                            ^
sandwich.cpp:56:35: warning: array subscript has type 'char' [-Wchar-subscripts]
   ret += dfs(nx, ny, dir[s[nx][ny]][t[s[x][y]][d][i]]);
                                   ^
sandwich.cpp:56:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   ret += dfs(nx, ny, dir[s[nx][ny]][t[s[x][y]][d][i]]);
                                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...