제출 #98086

#제출 시각아이디문제언어결과실행 시간메모리
98086OrtClickbait (COCI18_clickbait)C++14
120 / 120
28 ms5368 KiB
#include<iostream> #include<cctype> #include<string> #include<vector> #define MAX 1005 #define fst first #define sec second using namespace std; char mat[MAX][MAX]; int visited[MAX][MAX]; vector<int> sol; int n, m, start1i, start1j, nx, ny; pair<int,int> getnext_right(int y, int x) { while(true) { while((mat[y][x+1]=='-' || mat[y][x+1]=='+') && !visited[y][x+1]) {visited[y][x] = 3; x++;} if((mat[y-1][x+1]=='+' || mat[y-1][x+1]=='|') && (mat[y+1][x+1]=='+' || mat[y+1][x+1]=='|')) return make_pair(x+2,y); if((mat[y+1][x-1]=='+' || mat[y+1][x-1]=='-') && (mat[y+1][x+1]=='+' || mat[y+1][x-1]=='-')) return make_pair(x,y+2); while((mat[y+1][x]=='|' || mat[y+1][x]=='+') && !visited[y+1][x]) {visited[y][x] = 3; y++;} if((mat[y+1][x-1]=='+' || mat[y+1][x-1]=='-') && (mat[y+1][x+1]=='+' || mat[y+1][x-1]=='-')) return make_pair(x,y+2); if((mat[y-1][x+1]=='+' || mat[y-1][x+1]=='|') && (mat[y+1][x+1]=='+' || mat[y+1][x+1]=='|')) return make_pair(x+2,y); while((mat[y][x-1]=='-' || mat[y][x-1]=='+') && !visited[y][x-1]) {visited[y][x] = 3; x--;} if((mat[y-1][x+1]=='+' || mat[y-1][x+1]=='|') && (mat[y+1][x+1]=='+' || mat[y+1][x+1]=='|')) return make_pair(x+2,y); if((mat[y+1][x-1]=='+' || mat[y+1][x-1]=='-') && (mat[y+1][x+1]=='+' || mat[y+1][x+1]=='-')) return make_pair(x,y+1); } } pair<int,int> getnext_left(int y, int x) { while(true) { while((mat[y][x-1]=='-' || mat[y][x-1]=='+') && !visited[y][x-1]) {visited[y][x] = 3; x--;} if((mat[y-1][x+1]=='+' || mat[y-1][x+1]=='|') && (mat[y+1][x+1]=='+' || mat[y+1][x+1]=='|')) return make_pair(x+2,y); if((mat[y+1][x-1]=='+' || mat[y+1][x-1]=='-') && (mat[y+1][x+1]=='+' || mat[y+1][x-1]=='-')) return make_pair(x,y+2); while((mat[y+1][x]=='|' || mat[y+1][x]=='+') && !visited[y+1][x]) {visited[y][x] = 3; y++;} if((mat[y+1][x-1]=='+' || mat[y+1][x-1]=='-') && (mat[y+1][x+1]=='+' || mat[y+1][x-1]=='-')) return make_pair(x,y+2); if((mat[y-1][x+1]=='+' || mat[y-1][x+1]=='|') && (mat[y+1][x+1]=='+' || mat[y+1][x+1]=='|')) return make_pair(x+2,y); while((mat[y][x+1]=='-' || mat[y][x+1]=='+') && !visited[y][x+1]) {visited[y][x] = 3; x++;} if((mat[y-1][x+1]=='+' || mat[y-1][x+1]=='|') && (mat[y+1][x+1]=='+' || mat[y+1][x+1]=='|')) return make_pair(x+2,y); if((mat[y+1][x-1]=='+' || mat[y+1][x-1]=='-') && (mat[y+1][x+1]=='+' || mat[y+1][x+1]=='-')) return make_pair(x,y+1); } } int process(int y, int x) { string ss = ""; int l = x, r = x; while(isdigit(mat[y][l])) l--; l++; while(isdigit(mat[y][r])) r++; for(int j=l;j<r;j++) {visited[y][j] = 1; ss += (mat[y][j]);} return stoi(ss); } void traverse(int y, int x) { int num = -1; if(isdigit(mat[y][x]) && !visited[y][x]) num = process(y,x); while(mat[y+1][x]!='-' && mat[y+1][x]!='+') y++; while(mat[y-1][x]!='-' && mat[y-1][x]!='+') { int l = x; int r = x; while(mat[y][l-1]!='|') {if(isdigit(mat[y][l]) && !visited[y][l]) num = process(y,l); l--;} while(mat[y][r+1]!='|') {if(isdigit(mat[y][r]) && !visited[y][r]) num = process(y,r); r++;} if(isdigit(mat[y][l]) && !visited[y][l]) num = process(y,l); if(isdigit(mat[y][r]) && !visited[y][r]) num = process(y,r); if(mat[y][r+1]=='|' && mat[y][r+2]=='-') {pair<int,int> p = getnext_right(y, r+2); traverse(p.sec,p.first);} if(mat[y][l-1]=='|' && mat[y][l-2]=='-') {pair<int,int> p = getnext_left(y, l-2); traverse(p.sec,p.first);} y--; } int l = x; int r = x; while(mat[y][l-1]!='|') {if(isdigit(mat[y][l]) && !visited[y][l]) num = process(y,l); l--;} while(mat[y][r+1]!='|') {if(isdigit(mat[y][r]) && !visited[y][r]) num = process(y,r); r++;} if(isdigit(mat[y][l]) && !visited[y][l]) num = process(y,l); if(isdigit(mat[y][r]) && !visited[y][r]) num = process(y,r); if(mat[y][r+1]=='|' && mat[y][r+2]=='-') {pair<int,int> p = getnext_right(y, r+2); traverse(p.sec,p.first);} if(mat[y][l-1]=='|' && mat[y][l-2]=='-') {pair<int,int> p = getnext_left(y, l-2); traverse(p.sec,p.first);} sol.push_back(num); } int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); cin >> n >> m; for(int i=0;i<n+4;i++) for(int j=0;j<m+4;j++) mat[i][j] = '.'; for(int i=1;i<n+1;i++) for(int j=1;j<m+1;j++) cin >> mat[i][j]; for(int i=1;i<n+1;i++) for(int j=1;j<m+1;j++) {if(mat[i][j]=='1' && !isdigit(mat[i][j-1]) && !isdigit(mat[i][j+1])) {start1i = i; start1j = j;}}; traverse(start1i,start1j); for(auto i:sol) cout << i << "\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

clickbait.cpp: In function 'int process(int, int)':
clickbait.cpp:47:2: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
  while(isdigit(mat[y][l])) l--; l++;
  ^~~~~
clickbait.cpp:47:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
  while(isdigit(mat[y][l])) l--; l++;
                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...