submission_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 3 values | code stringlengths 1 522k | compiler_output stringlengths 43 10.2k |
|---|---|---|---|---|
s765002465 | p00481 | C++ | #include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,l,cnt,mx,my;
char a[1019][1019];
int vis[1019][1019];
pair<int,int> p[10],st;
int mov[4][2] = {1,0,0,-1,-1,0,0,1};
struct status
{
int x,y;
int ord;
int fx;
status(int a,int b,int c,int s)
{
x = a, y = b, ord = c, fx = s;
}
bool operator < (struct status t) const
{
if(ord != t.ord) return ord > t.ord;
else return fx > t.fx;
}
}tt[4];
void bfs(int x,int y,int color)
{
queue <struct status> q;
struct status temp(x,y,0,fabs(x-p[color].first) + fabs(y - p[color].second));
q.push(temp);
int flag = 0;
while(!q.empty())
{
struct status nw = q.top();
q.pop();
if(nw.x == p[color].first && nw.y == p[color].second)
{
cnt += nw.ord;
break;
}
vis[nw.x][nw.y] = 1;
for(int i=0;i<4;i++)
{
int tx = mov[i][0] + nw.x, ty = nw.y + mov[i][1];
if(tx>=0 && tx< n && ty>=0 && ty< m && !vis[tx][ty] && a[tx][ty] != 'X')
{
struct status tmp(tx,ty,nw.ord+1,fabs(tx-p[color].first) + fabs(ty - p[color].second));
tt[i] = tmp;
vis[tx][ty] = 1;
}
}
sort(tt,tt+4);
for(int i=0;i<4;i++) q.push(tt[i]);
}
}
int main()
{
while(~scanf("%d%d%d",&n,&m,&l))
{
getchar();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
scanf("%c",&a[i][j]);
if(a[i][j]>='0' && a[i][j]<='9')
p[a[i][j]-'0'].first = i, p[a[i][j]-'0'].second = j;
if(a[i][j] == 'S') st.first = i, st.second = j;
}
getchar();
}
int sx = st.first, sy = st.second;
cnt = 0;
for(int i=1;i<=l;i++)
{
memset(vis,0,sizeof(vis));
bfs(sx,sy,i);
sx = p[i].first, sy = p[i].second;
}
printf("%d\n",cnt);
}
return 0;
} | a.cc:28:6: error: no matching function for call to 'status::status()'
28 | }tt[4];
| ^
a.cc:19:5: note: candidate: 'status::status(int, int, int, int)'
19 | status(int a,int b,int c,int s)
| ^~~~~~
a.cc:19:5: note: candidate expects 4 arguments, 0 provided
a.cc:14:8: note: candidate: 'constexpr status::status(const status&)'
14 | struct status
| ^~~~~~
a.cc:14:8: note: candidate expects 1 argument, 0 provided
a.cc:14:8: note: candidate: 'constexpr status::status(status&&)'
a.cc:14:8: note: candidate expects 1 argument, 0 provided
a.cc: In function 'void bfs(int, int, int)':
a.cc:38:30: error: 'class std::queue<status>' has no member named 'top'; did you mean 'pop'?
38 | struct status nw = q.top();
| ^~~
| pop
|
s185373450 | p00481 | C++ | #include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int bfs();
int INF=1000000000;
int h,w,n;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int sx,sy;
int good[1111][1111];
int ans=0;
char life="0";
char map[1111][1111];
int main(){
cin >> h >> w >> n;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin >> map[i][j];
if(map[i][j] == 'S'){
sy = i;
sx = j;
}
}
}
for(int i=1;i<n+1;i++){
life++;
ans += bfs();
cout << ans << endl;
}
}
int bfs(){
pueue<P> pue;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
good[i][j] = INF;
}
}
pue.push(P(sy,sx));
d[sy][sx] = 0;
while(que.size()){
P p=pue.front(); que.pop();
if(map[p.first][p.second] < life){
sy = p.first;
sx = p.second;
break;
}
for(int i=0;i<4;i++){
int nx = p.first + dy[i];
int ny = p.second + dx[i];
if(0 <= nx && nx < N && 0 <= ny && ny < M && map[ny][nx] != 'X' && good[ny][nx] == INF){
good[ny][nx] = good[p.first][p.second] + 1;
}
}
}
return good[sy][sx];
} | a.cc:17:11: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
17 | char life="0";
| ^~~
| |
| const char*
a.cc: In function 'int main()':
a.cc:24:14: error: reference to 'map' is ambiguous
24 | cin >> map[i][j];
| ^~~
In file included from /usr/include/c++/14/map:63,
from a.cc:4:
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:18:6: note: 'char map [1111][1111]'
18 | char map[1111][1111];
| ^~~
a.cc:25:10: error: reference to 'map' is ambiguous
25 | if(map[i][j] == 'S'){
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:18:6: note: 'char map [1111][1111]'
18 | char map[1111][1111];
| ^~~
a.cc: In function 'int bfs()':
a.cc:40:3: error: 'pueue' was not declared in this scope
40 | pueue<P> pue;
| ^~~~~
a.cc:40:10: error: expected primary-expression before '>' token
40 | pueue<P> pue;
| ^
a.cc:40:12: error: 'pue' was not declared in this scope
40 | pueue<P> pue;
| ^~~
a.cc:47:3: error: 'd' was not declared in this scope
47 | d[sy][sx] = 0;
| ^
a.cc:49:9: error: 'que' was not declared in this scope
49 | while(que.size()){
| ^~~
a.cc:51:8: error: reference to 'map' is ambiguous
51 | if(map[p.first][p.second] < life){
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:18:6: note: 'char map [1111][1111]'
18 | char map[1111][1111];
| ^~~
a.cc:59:26: error: 'N' was not declared in this scope
59 | if(0 <= nx && nx < N && 0 <= ny && ny < M && map[ny][nx] != 'X' && good[ny][nx] == INF){
| ^
a.cc:59:47: error: 'M' was not declared in this scope
59 | if(0 <= nx && nx < N && 0 <= ny && ny < M && map[ny][nx] != 'X' && good[ny][nx] == INF){
| ^
a.cc:59:52: error: reference to 'map' is ambiguous
59 | if(0 <= nx && nx < N && 0 <= ny && ny < M && map[ny][nx] != 'X' && good[ny][nx] == INF){
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:18:6: note: 'char map [1111][1111]'
18 | char map[1111][1111];
| ^~~
|
s152261278 | p00481 | C++ | for( k = 0 ; k < h ; k++ ){
for( l = 0 ; l < w ; l++){
if(s[k][l] == 'S'){
x[0] = l; y[0] = k;
}
if('1' <= s[k][l] && s[k][l] <= '9'){
v = s[k][l]-'1'+1;
x[v] = l; y[v] = k;
}
}
}
for (k = 1 ; k <= n ; k++){
result += bfs(x[k-1],y[k-1],x[k],y[k]);
}
printf("%d\n", result);
return 0;
}
int bfs(int sx, int sy, int gx, int gy){
queue<int> Q;
int i, j;
int dx[4]={0, 1, 0, -1};
int dy[4]={1, 0, -1, 0};
for( i = 0 ; i < h ; i++ ){
for( j = 0 ; j < w ; j++ ){
d[i][j] = 100000;
}
}
Q.push(sy*w+sx);
d[sy][sx]=0; /*スタート地点の初期化*/
while( !Q.empty() ){
int u = Q.front(); Q.pop();
int pi = u/w;
int pj = u%w;
if( pi == gy && pj == gx )return d[gy][gx];
for ( int r = 0; r < 4; r++ ){
int ni = pi + dy[r];
int nj = pj + dx[r];
if ( ni < 0 || nj < 0 || ni >= h || nj >= w ) continue;
if ( s[ni][nj] == 'X' ) continue;
if( d[ni][nj] > d[pi][pj]+1 ){
d[ni][nj] = d[pi][pj] + 1;
Q.push( ni * w + nj );
}
}
}
// printf("%d\n",u);
return -1;
} | a.cc:1:3: error: expected unqualified-id before 'for'
1 | for( k = 0 ; k < h ; k++ ){
| ^~~
a.cc:1:16: error: 'k' does not name a type
1 | for( k = 0 ; k < h ; k++ ){
| ^
a.cc:1:24: error: 'k' does not name a type
1 | for( k = 0 ; k < h ; k++ ){
| ^
a.cc:12:3: error: expected unqualified-id before 'for'
12 | for (k = 1 ; k <= n ; k++){
| ^~~
a.cc:12:16: error: 'k' does not name a type
12 | for (k = 1 ; k <= n ; k++){
| ^
a.cc:12:25: error: 'k' does not name a type
12 | for (k = 1 ; k <= n ; k++){
| ^
a.cc:16:9: error: expected constructor, destructor, or type conversion before '(' token
16 | printf("%d\n", result);
| ^
a.cc:17:3: error: expected unqualified-id before 'return'
17 | return 0;
| ^~~~~~
a.cc:18:1: error: expected declaration before '}' token
18 | }
| ^
a.cc: In function 'int bfs(int, int, int, int)':
a.cc:21:3: error: 'queue' was not declared in this scope
21 | queue<int> Q;
| ^~~~~
a.cc:21:9: error: expected primary-expression before 'int'
21 | queue<int> Q;
| ^~~
a.cc:27:21: error: 'h' was not declared in this scope
27 | for( i = 0 ; i < h ; i++ ){
| ^
a.cc:28:22: error: 'w' was not declared in this scope
28 | for( j = 0 ; j < w ; j++ ){
| ^
a.cc:29:7: error: 'd' was not declared in this scope; did you mean 'dy'?
29 | d[i][j] = 100000;
| ^
| dy
a.cc:33:3: error: 'Q' was not declared in this scope
33 | Q.push(sy*w+sx);
| ^
a.cc:33:13: error: 'w' was not declared in this scope
33 | Q.push(sy*w+sx);
| ^
a.cc:34:3: error: 'd' was not declared in this scope; did you mean 'dy'?
34 | d[sy][sx]=0; /*スタート地点の初期化*/
| ^
| dy
a.cc:44:38: error: 'h' was not declared in this scope
44 | if ( ni < 0 || nj < 0 || ni >= h || nj >= w ) continue;
| ^
a.cc:45:12: error: 's' was not declared in this scope
45 | if ( s[ni][nj] == 'X' ) continue;
| ^
|
s286187852 | p00481 | C++ | #include <stdio.h>
#include <queue>
using namespace std;
int d[1000][1000], sx, sy;
char s[1000][1000];
int h,w,n;
int k, l;
int bfs(int,int,int,int);
int main(){
int result = 0;
int x[10], y[10], v;
scanf("%d %d %d", &h, &w, &n);
for(k = 0 ; k < h ; k++){
scanf("%s",s[k]);javascript:void(0)
}
for( k = 0 ; k < h ; k++ ){
for( l = 0 ; l < w ; l++){
if(s[k][l] == 'S'){
x[0] = l; y[0] = k;
}
if('1' <= s[k][l] && s[k][l] <= '9'){
v = s[k][l]-'1'+1;
x[v] = l; y[v] = k;
}
}
}
for (k = 1 ; k <= n ; k++){
result += bfs(x[k-1],y[k-1],x[k],y[k]);
}
printf("%d\n", result);
return 0;
}
int bfs(int sx, int sy, int gx, int gy){
queue<int> Q;
int i, j;
int dx[4]={0, 1, 0, -1};
int dy[4]={1, 0, -1, 0};
for( i = 0 ; i < h ; i++ ){
for( j = 0 ; j < w ; j++ ){
d[i][j] = 100000;
}
}
Q.push(sy*w+sx);
d[sy][sx]=0; /*スタート地点の初期化*/
while( !Q.empty() ){
int u = Q.front(); Q.pop();
int pi = u/w;
int pj = u%w;
if( pi == gy && pj == gx )return d[gy][gx];
for ( int r = 0; r < 4; r++ ){
int ni = pi + dy[r];
int nj = pj + dx[r];
if ( ni < 0 || nj < 0 || ni >= h || nj >= w ) continue;
if ( s[ni][nj] == 'X' ) continue;
if( d[ni][nj] > d[pi][pj]+1 ){
d[ni][nj] = d[pi][pj] + 1;
Q.push( ni * w + nj );
}
}
}
// printf("%d\n",u);
return -1;
} | a.cc: In function 'int main()':
a.cc:16:42: error: expected ';' before '}' token
16 | scanf("%s",s[k]);javascript:void(0)
| ^
| ;
17 | }
| ~
|
s950070907 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int sx,sy;
typedef struct place
{
int x;
int y;
}P;
char map[1005][1005];
int d[1005][1005];
int dd[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int ans;
int h,w,n;
int tempx,tempy;
void bfs(int i,int j,int n)
{
queue<P> q;
P p1={i,j};
q.push(p1);
d[i][j]=0;
while(q.size())
{
P p=q.front();
q.pop();
if(map[p.x][p.y]==n+48)
{
tempx=p.x;
tempy=p.y;
ans+=d[p.x][p.y];
break;
}
for(int i=0;i<4;i++)
{
int nx=p.x+dd[i][0];
int ny=p.y+dd[i][1];
if(map[nx][ny]!='X' && nx>=0 && ny>=0 && nx<=h && ny<=w && d[nx][ny]==-1)
{
d[nx][ny]=d[p.x][p.y]+1;
P p1={nx,ny};
q.push(p1);
}
}
}
}
int main()
{
while(scanf("%d %d %d",&h,&w,&n)!=EOF)
{
ans=0;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
cin>>map[i][j];
d[i][j]=-1;
if(map[i][j]=='S')
{
sx=i;
sy=j;
}
}
}
tempx=sx;
tempy=sy;
for(int l=1;l<=n;l++)
{
memset(d,-1,sizeof(d));
bfs(tempx,tempy,l);
}
cout<<ans<<endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:75:25: error: 'memset' was not declared in this scope
75 | memset(d,-1,sizeof(d));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 |
|
s847398694 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int maxn = 1010;
typedef struct Point
{
int x, y, t, n;
Point(int _x, int _y, int _t)
{
x = _x, y =_y, t = _t;
}
};
char a[maxn][maxn];
bool vis[maxn][maxn];
int W, H, N;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int data[16][2];
int BFS(int sx, int sy, int ex, int ey)
{
queue<Point> que;
que.push(Point(sx, sy, 0));
memset(vis, 0, sizeof(vis));
vis[sx][sy] = 1;
while(!que.empty())
{
Point p = que.front(); que.pop();
//cout<<"p.t: "<<p.t<<endl;
if(p.x == ex && p.y == ey) return p.t;
for(int i = 0; i < 4; i++)
{
int nx = p.x + dx[i];
int ny = p.y + dy[i];
//cout<<nx<<" "<<ny<<" "<<vis[nx][ny]<<endl;
if(nx >= 0 && nx < H && ny >= 0 && ny < W && a[nx][ny] != 'X' && vis[nx][ny] == 0)
{
//cout<<"nx: "<<nx<<" ny: "<<ny<<" nn "<<nn<<" a[nx][ny] "<<a[nx][ny]<<endl;
que.push(Point(nx, ny, p.t + 1));
vis[nx][ny] = 1;
}
}
}
/* for(int i = 0; i < H; i++)
{
for(int j = 0; j < W; j++)
cout<<vis[i][j];
cout<<endl;
}*/
return 0;
}
int main()
{
//FILE *f = fopen("data.txt","rb");
scanf("%d%d%d", &H, &W, &N)
int sx, sy, ans = 0;
for(int i = 0; i < H; i++)
scanf("%s",a[i]);
for(int i = 0; i < H; i++)
for(int j = 0; j < W; j++)
if(a[i][j] == 'S') {data[0][0] = i, data[0][1] =j; a[i][j] = '.'; break;}
else if( isdigit(a[i][j]) )
{
int index = a[i][j] - '0';
data[index][0] = i;
data[index][1] = j;
}
for(int i = 0; i < N; i++)
{
ans += BFS(data[i][0], data[i][1], data[i+1][0], data[i+1][1]);
}
printf("%d\n",ans);
return 0;
} | a.cc:8:1: warning: 'typedef' was ignored in this declaration
8 | typedef struct Point
| ^~~~~~~
a.cc: In function 'int main()':
a.cc:61:32: error: expected ';' before 'int'
61 | scanf("%d%d%d", &H, &W, &N)
| ^
| ;
62 |
63 | int sx, sy, ans = 0;
| ~~~
a.cc:70:38: error: reference to 'data' is ambiguous
70 | if(a[i][j] == 'S') {data[0][0] = i, data[0][1] =j; a[i][j] = '.'; break;}
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:5: note: 'int data [16][2]'
21 | int data[16][2];
| ^~~~
a.cc:70:54: error: reference to 'data' is ambiguous
70 | if(a[i][j] == 'S') {data[0][0] = i, data[0][1] =j; a[i][j] = '.'; break;}
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:5: note: 'int data [16][2]'
21 | int data[16][2];
| ^~~~
a.cc:74:21: error: reference to 'data' is ambiguous
74 | data[index][0] = i;
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:5: note: 'int data [16][2]'
21 | int data[16][2];
| ^~~~
a.cc:75:21: error: reference to 'data' is ambiguous
75 | data[index][1] = j;
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:5: note: 'int data [16][2]'
21 | int data[16][2];
| ^~~~
a.cc:79:13: error: 'ans' was not declared in this scope; did you mean 'abs'?
79 | ans += BFS(data[i][0], data[i][1], data[i+1][0], data[i+1][1]);
| ^~~
| abs
a.cc:79:24: error: reference to 'data' is ambiguous
79 | ans += BFS(data[i][0], data[i][1], data[i+1][0], data[i+1][1]);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:5: note: 'int data [16][2]'
21 | int data[16][2];
| ^~~~
a.cc:79:36: error: reference to 'data' is ambiguous
79 | ans += BFS(data[i][0], data[i][1], data[i+1][0], data[i+1][1]);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:5: note: 'int data [16][2]'
21 | int data[16][2];
| ^~~~
a.cc:79:49: error: reference to 'data' is ambiguous
79 | ans += BFS(data[i][0], data[i][1], data[i+1][0], data[i+1][1]);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:5: note: 'int data [16][2]'
21 | int data[16][2];
| ^~~~
a.cc:79:63: error: reference to 'data' is ambiguous
79 | ans += BFS(data[i][0], data[i][1], data[i+1][0], data[i+1][1]);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Contain |
s469698110 | p00481 | C++ | #include <iostream>
#include <queue>
#include <algorithm>
#define N 1005
#define INFINITY 2000000000
using namespace std;
void bfs();
int h,w,n,num[N][N],d[N*N],M[N*N][N*N],u,m;
string color[N*N],in[N*N];
int main(){
int i,j,k;
cin >> h >> w >> n;
for(i=0;i<h+2;i++)
for(j=0;j<w+2;j++)
num[i][j]=-1;
for(i=1;i<=h;i++) cin >> in[i],in[i]='X'+in[i];
k=0;
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
if(in[i][j]!='X') num[i][j]=k,k++;
}
}
m=max(h,w);
for(i=0;i<=m;i++)
for(j=0;j<=m;j++)
M[i][j]=0;
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
if(num[i][j]!=-1&&num[i+1][j]!=-1)
M[num[i][j]][num[i+1][j]]=M[num[i+1][j]][num[i][j]]=1;
if(num[i][j]!=-1&&num[i][j+1]!=-1)
M[num[i][j]][num[i][j+1]]=M[num[i][j+1]][num[i][j]]=1;
}
}
bfs();
return 0;
}
void bfs(){
int i,j,p=1,t=0,flag=0,x=1;
char start='S',goal='1';
queue<int> q;
while(1){
if(flag==1) start=x+'0',goal=x+'0'+1,x++;
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
color[num[i][j]]="WHITE",d[num[i][j]]=INFINITY;
}
}
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
if(in[i][j]==start) color[num[i][j]]="GLAY",d[num[i][j]]=0,q.push(num[i][j]);
}
}
while(q.empty()!=1){
u=q.front();
q.pop();
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
if(M[u][num[i][j]]&&color[num[i][j]]=="WHITE"){
color[num[i][j]]="GLAY";
d[num[i][j]]=d[u]+1;
q.push(num[i][j]);
}
}
}
color[u]="BLACK";
}
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
if(in[i][j]==goal) t+=d[num[i][j]];
}
}
flag=1;
if(x>n) break;
}
cout << t << endl;
} | /tmp/ccgxHeUm.o: in function `main':
a.cc:(.text+0xc7): relocation truncated to fit: R_X86_64_PC32 against symbol `in[abi:cxx11]' defined in .bss section in /tmp/ccgxHeUm.o
a.cc:(.text+0xef): relocation truncated to fit: R_X86_64_PC32 against symbol `in[abi:cxx11]' defined in .bss section in /tmp/ccgxHeUm.o
a.cc:(.text+0x116): relocation truncated to fit: R_X86_64_PC32 against symbol `in[abi:cxx11]' defined in .bss section in /tmp/ccgxHeUm.o
a.cc:(.text+0x173): relocation truncated to fit: R_X86_64_PC32 against symbol `in[abi:cxx11]' defined in .bss section in /tmp/ccgxHeUm.o
a.cc:(.text+0x203): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccgxHeUm.o
a.cc:(.text+0x24a): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccgxHeUm.o
a.cc:(.text+0x259): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccgxHeUm.o
/tmp/ccgxHeUm.o: in function `bfs()':
a.cc:(.text+0x62e): relocation truncated to fit: R_X86_64_PC32 against symbol `color[abi:cxx11]' defined in .bss section in /tmp/ccgxHeUm.o
a.cc:(.text+0x6d3): relocation truncated to fit: R_X86_64_PC32 against symbol `in[abi:cxx11]' defined in .bss section in /tmp/ccgxHeUm.o
a.cc:(.text+0x72e): relocation truncated to fit: R_X86_64_PC32 against symbol `color[abi:cxx11]' defined in .bss section in /tmp/ccgxHeUm.o
a.cc:(.text+0x7f7): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
|
s150248232 | p00481 | C++ | #include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
queue < pair<int, int> > q;
pair<int, int> p;
char **m;
char c[10] = { "123456789" };
int **f;
bool flg = false;
int n, k, i, i1, c1, i2, sum = 0;
cin >> n;
cin >> k;
cin >> c1;
m = new char *[n + 2];
f = new int *[n + 2];
for (i = 0; i < n + 2; i++){
m[i] = new char[k + 2];
f[i] = new int[k + 2];
}
for (i = 1; i <= n; i++){
for (i1 = 1; i1 <= k; i1++){
cin >> m[i][i1];
}
}
for (i = 0; i < n + 2; i++){
for (i1 = 0; i1 < k + 2; i1++){
if (i == 0 || i == n + 1){
m[i][i1] = 'X';
}
else if (i1 == 0 || i1 == k + 1){
m[i][i1] = 'X';
}
}
}
for (i = 1; i <= n; i++){
for (i1 = 1; m[i][i1] != '\0'; i1++){
if (m[i][i1] == 'S'){
q.push(make_pair(i, i1));
}
}
}
pair<int, int> temp;
temp = q.front();
for (i = 0; i < c1; i++){
for (i1 = 0; i1 < n + 2; i1++){
for (i2 = 0; i2 < k + 2; i2++){
if ((i1 == 0 || i1 == n + 1) && !flg){
f[i1][i2] = 1;
}
else if ((i2 == 0 || i2 == k + 1) && !flg){
f[i1][i2] = 1;
}
else
f[i1][i2] = -1;
}
}
flg = true;
}
f[temp.first][temp.second] = 0;
while (!q.empty()){
p = q.front();
q.pop();
int x[4] = { -1, 1, 0, 0 }, y[4] = { 0, 0, -1, 1 };
for (int j = 0; j < 4; j++){
//???????????´??????????´¢
if (m[p.first + x[j]][p.second + y[j]] != 'X' && f[p.first + x[j]][p.second + y[j]] < 0){
q.push(make_pair(p.first + x[j], p.second + y[j]));
f[p.first + x[j]][p.second + y[j]] = f[p.first][p.second] + 1;
}
}
//??´?????????????????????
if (m[p.first][p.second] == c[i]){
sum += f[p.first][p.second];
temp = p;
while (!q.empty()){
q.pop();
}
q.push(p);
break;
}
}
}
cout << sum << endl;
return 0;
} | a.cc:113:5: error: 'cout' does not name a type
113 | cout << sum << endl;
| ^~~~
a.cc:115:5: error: expected unqualified-id before 'return'
115 | return 0;
| ^~~~~~
a.cc:116:1: error: expected declaration before '}' token
116 | }
| ^
|
s947655493 | p00481 | C++ | #include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int m,n,t;
int cnt;
char c;
char map[1010][1010];
bool vis[1010][1010];
struct node
{
int x,y;
int step;
}start;
int way[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
void bfs()
{
queue <node> abc;
abc.push(start);
while(!abc.empty())
{
node k = abc.front();
abc.pop();
if(map[k.y][k.x] == c)
{
cnt+=k.step;
k.step = 0;
memset(vis,0,sizeof(vis));
while(!abc.empty())
abc.pop();
c++;
t--;
}
if(t==0)
{
return;
}
for(int i = 0;i<4;i++)
{
int dx = k.x+way[i][0];
int dy = k.y+way[i][1];
if(dx>=0 && dx<n && dy>=0 && dy<m && !vis[dy][dx] &&map[dy][dx]!='X')
{
node temp;
temp.x = dx;
temp.y = dy;
temp.step = k.step+1;
abc.push(temp);
vis[dy][dx]=1;
}
}
}
}
int main()
{
while(cin >> m >> n >> t)
{
cnt = 0;
c = '1';
memset(vis,0,sizeof(vis));
memset(map,0,sizeof(map));
for(int i = 0;i<m;i++)
{
for(int j = 0;j<n;j++)
{
cin >> map[i][j];
if(map[i][j] == 'S')
{
start.x = j;
start.y = i;
start.step = 0;
}
}
}
bfs();
cout << cnt << endl;
}
return 0;
} | a.cc: In function 'void bfs()':
a.cc:28:25: error: 'memset' was not declared in this scope
28 | memset(vis,0,sizeof(vis));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <algorithm>
+++ |+#include <cstring>
4 | using namespace std;
a.cc: In function 'int main()':
a.cc:60:17: error: 'memset' was not declared in this scope
60 | memset(vis,0,sizeof(vis));
| ^~~~~~
a.cc:60:17: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
|
s658290635 | p00481 | C++ | #include <memory>
#include <cstring>
#include <string>
#include <memory.h>
using namespace std;
int m,n,t;
int cnt;
char c;
char map[1010][1010];
bool vis[1010][1010];
struct node
{
int x,y;
int step;
}start;
int way[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
void bfs()
{
queue <node> abc;
abc.push(start);
while(!abc.empty())
{
node k = abc.front();
abc.pop();
if(map[k.y][k.x] == c)
{
cnt+=k.step;
k.step = 0;
memset(vis,0,sizeof(vis));
while(!abc.empty())
abc.pop();
c++;
t--;
}
if(t==0)
{
return;
}
for(int i = 0;i<4;i++)
{
int dx = k.x+way[i][0];
int dy = k.y+way[i][1];
if(dx>=0 && dx<n && dy>=0 && dy<m && !vis[dy][dx] &&map[dy][dx]!='X')
{
node temp;
temp.x = dx;
temp.y = dy;
temp.step = k.step+1;
abc.push(temp);
vis[dy][dx]=1;
}
}
}
}
int main()
{
while(cin >> m >> n >> t)
{
cnt = 0;
c = '1';
memset(vis,0,sizeof(vis));
memset(map,0,sizeof(map));
for(int i = 0;i<m;i++)
{
for(int j = 0;j<n;j++)
{
cin >> map[i][j];
if(map[i][j] == 'S')
{
start.x = j;
start.y = i;
start.step = 0;
}
}
}
bfs();
cout << cnt << endl;
}
return 0;
} | a.cc: In function 'void bfs()':
a.cc:19:9: error: 'queue' was not declared in this scope
19 | queue <node> abc;
| ^~~~~
a.cc:5:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
4 | #include <memory.h>
+++ |+#include <queue>
5 | using namespace std;
a.cc:19:20: error: expected primary-expression before '>' token
19 | queue <node> abc;
| ^
a.cc:19:22: error: 'abc' was not declared in this scope; did you mean 'abs'?
19 | queue <node> abc;
| ^~~
| abs
a.cc: In function 'int main()':
a.cc:57:15: error: 'cin' was not declared in this scope
57 | while(cin >> m >> n >> t)
| ^~~
a.cc:5:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
4 | #include <memory.h>
+++ |+#include <iostream>
5 | using namespace std;
a.cc:77:17: error: 'cout' was not declared in this scope
77 | cout << cnt << endl;
| ^~~~
a.cc:77:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:77:32: error: 'endl' was not declared in this scope
77 | cout << cnt << endl;
| ^~~~
a.cc:5:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
4 | #include <memory.h>
+++ |+#include <ostream>
5 | using namespace std;
|
s421948462 | p00481 | C++ | #include <cstdio>
#include <iostream>
#include <queue>
#include <map>
#include <string>
using namespace std;
typedef struct P{
int x;
int y;
};
int h,w;
const int INF = 100000000;
char feld[101][101];
P ch[11];
int d[101][101];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int sx,sy;
int gx,gy;
int n;
int ans;
int bfs(){
for(int i=0;i<n;i++){
P s_xy=ch[i];
sx=ch[i].x;
sy=ch[i].y;
gx=ch[i+1].x;
gy=ch[i+1].y;
for(int y=0;y<h;y++)
for(int x=0;x<w;x++)
d[y][x]=INF;
queue<P> que;
que.push(s_xy);
d[sy][sx]=0;
while(!que.empty()){
P p=que.front();
que.pop();
int x=p.x;
int y=p.y;
if(x==gx&&y==gy){
ans+=d[gy][gx];
break;
}
for(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if(nx<0||nx>=w||ny<0||ny>=h)continue;
if(feld[ny][nx]!='X'&&d[ny][nx]==INF){
P n;
n.x=nx;
n.y=ny;
d[ny][nx]=d[y][x]+1;
que.push(n);
}
}
}
}
return
}
int main(){
cin>>w>>h>>n;
char c;
for(int y=0;y<h;y++){
for(int x=0;x<w;x++){
scanf(" %c",&feld[y][x]);
c=feld[y][x];
if(feld[y][x]=='S'){
ch[0].x=x;
ch[0].y=y;
}
if(c>='1'&&c<='9'){
ch[c-'0'].x=x;
ch[c-'0'].y=y;
}
}
}
bfs();
cout<<ans<<endl;
return 0;
} | a.cc:9:1: warning: 'typedef' was ignored in this declaration
9 | typedef struct P{
| ^~~~~~~
a.cc: In function 'int bfs()':
a.cc:66:1: error: expected primary-expression before '}' token
66 | }
| ^
a.cc:65:15: error: expected ';' before '}' token
65 | return
| ^
| ;
66 | }
| ~
|
s457738157 | p00481 | C++ | #include<iostream>
#include<cstdio>
#include<queue>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
struct P{
int x;
int y;
};
int w,h,n;
const int INF = 1e+8;
char feld[1010][1010];
int d[1010][1010];
int sx,sy,gx,gy;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int ans=0;
P che[15];
int bfs(){
for(int i=0;i<n,i++){
P sp=che[i];
sx=che[i].x;
sy=che[i].y;
gx=che[i+1].x;
gy=che[i+1].y;
queue<P> que;
for(int y=0;y<h;y++)for(int x=0;x<w;x++)d[y][x]=INF;
que.push(sp);
d[sy][sx]=0;
while(!que.empty()){
P p=que.front();
que.pop();
int x=p.x;
int y=p.y;
if(x==gx&&y==gy){
ans+=d[gy][gx];
break;
}
REP(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if(nx<0||ny<0&&nx>=w&&ny>=h)continue;
if(feld[ny][nx]!='X'&&d[ny][nx]==INF){
P next;
next.x=nx;
next.y=ny;
que.push(next);
d[ny][nx]=d[y][x]+1;
}
}
}
}
return 0;
}
int main(){
cin>>h>>w>>n;
REP(int y=0;y<h;y++){
REP(int x=0;x<w;x++){
scanf(" %c",&feld[y][x]);
if(feld[y][x]=='S'){
che[0].x=x;
che[0].y=y;
}else if(feld[y][x]>='1'&&feld[y][x]<='9'){
char c=feld[y][x];
che[c-'0'].x=x;
che[c-'0'].y=y;
}
}
}
bfs();
cout<<ans<<endl;
return 0;
} | a.cc:46:32: error: macro "REP" requires 2 arguments, but only 1 given
46 | REP(int i=0;i<4;i++){
| ^
a.cc:4:9: note: macro "REP" defined here
4 | #define REP(i,n) for(int i=0;i<(n);i++)
| ^~~
a.cc:65:24: error: macro "REP" requires 2 arguments, but only 1 given
65 | REP(int y=0;y<h;y++){
| ^
a.cc:4:9: note: macro "REP" defined here
4 | #define REP(i,n) for(int i=0;i<(n);i++)
| ^~~
a.cc:66:28: error: macro "REP" requires 2 arguments, but only 1 given
66 | REP(int x=0;x<w;x++){
| ^
a.cc:4:9: note: macro "REP" defined here
4 | #define REP(i,n) for(int i=0;i<(n);i++)
| ^~~
a.cc: In function 'int bfs()':
a.cc:27:24: error: expected ';' before ')' token
27 | for(int i=0;i<n,i++){
| ^
| ;
a.cc:46:13: error: 'REP' was not declared in this scope
46 | REP(int i=0;i<4;i++){
| ^~~
a.cc: In function 'int main()':
a.cc:65:5: error: 'REP' was not declared in this scope
65 | REP(int y=0;y<h;y++){
| ^~~
|
s923412277 | p00481 | C++ | #include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int m,n;
int maxe=0;
int che=0;
int k;
struct node{
int x,y;
};
char mape[1111][1111];
int d[1111][1111];
queue<node> q;
int da[]={0,0,1,-1};
int db[]={1,-1,0,0};
void bfs(){
while(!q.empty()&&che<k){
node nn;
int x=q.front().x;
int y=q.front().y;
q.pop();
if(mape[x][y]>='0'&&mape[x][y]<='9'){
che++;
maxe+=d[x][y];
}
else mape[x][y]='X';
for(int i=0;i<4;i++)
if(x+da[i]>=0&&x+da[i]<m&&y+db[i]>=0&&y+db[i]<n&&mape[x+da[i]][y+db[i]]!='X'){
int w=x+da[i];
int e=y+db[i];
d[w][e]=d[x][y]+1;
nn.x=w;
nn.y=e;
mape[w][e]='X'
q.push(nn);
}
}
}
int main(){
cin>>m>>n>>k;
while(!q.empty())q.pop();
node nn;
memset(d,-1,sizeof(d));
for(int i=0;i<m;i++)
for(int j=0;j<n;j++){
cin>>mape[i][j];
if(mape[i][j]=='S'){
nn.x=i;
nn.y=j;
d[i][j]=0;
q.push(nn);
mape[i][j]='X';
}
}
bfs();
cout<<maxe<<"\n";
} | a.cc: In function 'void bfs()':
a.cc:35:23: error: expected ';' before 'q'
35 | mape[w][e]='X'
| ^
| ;
36 | q.push(nn);
| ~
|
s692925014 | p00481 | C++ | #include<iostream>
#include<queue>
#include<stdlib.h>
#include<pair.h>
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const int INF=-1;
char plat[1005][1005];
int d[1005][1005];
typedef pair<int,int> p;
int H,W,N;
queue<p> cheese;
int bfs(int& sx,int& sy,char energy)
{
d[sx][sy]=0;
cheese.push(p(sx,sy));
while(cheese.size()){
p test=cheese.front();
cheese.pop();
if(plat[test.first][test.second]==energy){
sx=test.first;sy=test.second;
return d[test.first][test.second];
}
for(int i=0;i<4;++i){
int nx=test.first+dx[i];int ny=test.second+dy[i];
if(nx>=0&&nx<W&&ny>=0&&ny<H&&plat[nx][ny]!='X'&&d[nx][ny]==INF){
cheese.push(p(nx,ny));
d[nx][ny]=d[test.first][test.second]+1;
}
}
}
}
int main()
{
cin>>W>>H>>N;
int sx,sy;
for(int i=0;i<W;++i){
for(int j=0;j<H;++j){
char u;
cin>>u;
if(u=='S'){
sx=i;sy=j;
}
plat[i][j]=u;
}
}
char e='1';
int ans=0;
while(N--){
memset(d,-1,sizeof(d));
ans+=bfs(sx,sy,e++);
while(cheese.size())cheese.pop();
}
cout<<ans<<endl;
} | a.cc:4:9: fatal error: pair.h: No such file or directory
4 | #include<pair.h>
| ^~~~~~~~
compilation terminated.
|
s498905363 | p00481 | C++ | #include<iostream>
#include<queue>
#include<stdlib.h>
#include<utility>
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const int INF=-1;
char plat[1005][1005];
int d[1005][1005];
typedef pair<int,int> p;
int H,W,N;
queue<p> cheese;
int bfs(int& sx,int& sy,char energy)
{
d[sx][sy]=0;
cheese.push(p(sx,sy));
while(cheese.size()){
p test=cheese.front();
cheese.pop();
if(plat[test.first][test.second]==energy){
sx=test.first;sy=test.second;
return d[test.first][test.second];
}
for(int i=0;i<4;++i){
int nx=test.first+dx[i];int ny=test.second+dy[i];
if(nx>=0&&nx<W&&ny>=0&&ny<H&&plat[nx][ny]!='X'&&d[nx][ny]==INF){
cheese.push(p(nx,ny));
d[nx][ny]=d[test.first][test.second]+1;
}
}
}
}
int main()
{
cin>>W>>H>>N;
int sx,sy;
for(int i=0;i<W;++i){
for(int j=0;j<H;++j){
char u;
cin>>u;
if(u=='S'){
sx=i;sy=j;
}
plat[i][j]=u;
}
}
char e='1';
int ans=0;
while(N--){
memset(d,-1,sizeof(d));
ans+=bfs(sx,sy,e++);
while(cheese.size())cheese.pop();
}
cout<<ans<<endl;
} | a.cc: In function 'int main()':
a.cc:53:9: error: 'memset' was not declared in this scope
53 | memset(d,-1,sizeof(d));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include<utility>
+++ |+#include <cstring>
5 | using namespace std;
a.cc: In function 'int bfs(int&, int&, char)':
a.cc:33:1: warning: control reaches end of non-void function [-Wreturn-type]
33 | }
| ^
|
s764420514 | p00481 | C++ | #include<iostream>
#include<queue>
#include<stdlib.h>
#include<utility>
#include<memory>
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const int INF=-1;
char plat[1005][1005];
int d[1005][1005];
typedef pair<int,int> p;
int H,W,N;
queue<p> cheese;
int bfs(int& sx,int& sy,char energy)
{
d[sx][sy]=0;
cheese.push(p(sx,sy));
while(cheese.size()){
p test=cheese.front();
cheese.pop();
if(plat[test.first][test.second]==energy){
sx=test.first;sy=test.second;
return d[test.first][test.second];
}
for(int i=0;i<4;++i){
int nx=test.first+dx[i];int ny=test.second+dy[i];
if(nx>=0&&nx<W&&ny>=0&&ny<H&&plat[nx][ny]!='X'&&d[nx][ny]==INF){
cheese.push(p(nx,ny));
d[nx][ny]=d[test.first][test.second]+1;
}
}
}
}
int main()
{
cin>>W>>H>>N;
int sx,sy;
for(int i=0;i<W;++i){
for(int j=0;j<H;++j){
char u;
cin>>u;
if(u=='S'){
sx=i;sy=j;
}
plat[i][j]=u;
}
}
char e='1';
int ans=0;
while(N--){
memset(d,-1,sizeof(d));
ans+=bfs(sx,sy,e++);
while(cheese.size())cheese.pop();
}
cout<<ans<<endl;
} | a.cc: In function 'int main()':
a.cc:54:9: error: 'memset' was not declared in this scope
54 | memset(d,-1,sizeof(d));
| ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
5 | #include<memory>
+++ |+#include <cstring>
6 | using namespace std;
a.cc: In function 'int bfs(int&, int&, char)':
a.cc:34:1: warning: control reaches end of non-void function [-Wreturn-type]
34 | }
| ^
|
s059567392 | p00481 | C++ | #include<iostream>
#include<queue>
#include<stdlib.h>
#include<utility>
#include<memory>
#include<string>
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const int INF=-1;
char plat[1005][1005];
int d[1005][1005];
typedef pair<int,int> p;
int H,W,N;
queue<p> cheese;
int bfs(int& sx,int& sy,char energy)
{
d[sx][sy]=0;
cheese.push(p(sx,sy));
while(cheese.size()){
p test=cheese.front();
cheese.pop();
if(plat[test.first][test.second]==energy){
sx=test.first;sy=test.second;
return d[test.first][test.second];
}
for(int i=0;i<4;++i){
int nx=test.first+dx[i];int ny=test.second+dy[i];
if(nx>=0&&nx<W&&ny>=0&&ny<H&&plat[nx][ny]!='X'&&d[nx][ny]==INF){
cheese.push(p(nx,ny));
d[nx][ny]=d[test.first][test.second]+1;
}
}
}
}
int main()
{
cin>>W>>H>>N;
int sx,sy;
for(int i=0;i<W;++i){
for(int j=0;j<H;++j){
char u;
cin>>u;
if(u=='S'){
sx=i;sy=j;
}
plat[i][j]=u;
}
}
char e='1';
int ans=0;
while(N--){
memset(d,-1,sizeof(d));
ans+=bfs(sx,sy,e++);
while(cheese.size())cheese.pop();
}
cout<<ans<<endl;
} | a.cc: In function 'int main()':
a.cc:55:9: error: 'memset' was not declared in this scope
55 | memset(d,-1,sizeof(d));
| ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
5 | #include<memory>
+++ |+#include <cstring>
6 | #include<string>
a.cc: In function 'int bfs(int&, int&, char)':
a.cc:35:1: warning: control reaches end of non-void function [-Wreturn-type]
35 | }
| ^
|
s719822502 | p00481 | C++ | #include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int h, w, n;
char map[1001][1001];
int vis[1001][1001];
const int v[2][4] = { {1,0,-1,0},{0,-1,0,1} };
queue<pair<int ,int>> Pos;
queue <pair<int, pair< int, int > >> que;//?????°?????§?¨?
int main() {
cin >> h >> w >> n;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> map[i][j];
if (map[i][j] == 'S')que.push(make_pair(0,make_pair(i,j)));
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= h; j++) {
for (int k = 1; k <= w; k++) {
if (map[j][k] - '0' == i)Pos.push(make_pair(j,k));
}
}
}
int ct = 0;
while (Pos.size()) {
pair<int, int > P = Pos.front();
hPos.pop();
while (que.size()) {
pair<int,pair< int,int > > a = que.front();
que.pop();
if (vis[a.second.first][a.second.second] != 0)continue;
vis[a.second.first][a.second.second] = a.first + 1;
if (a.second.first == P.first&&a.second.second == P.second) {
ct += vis[a.second.first][a.second.second];
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
vis[i][j] = 0;
}
}
while (que.size())que.pop();
if(Pos.size())que.push(make_pair(0,make_pair(a.second.first,a.second.second)));
ct -= 1;
break;
}
for (int i = 0; i < 4; i++) {
int px= a.second.first + v[0][i], py= a.second.second + v[1][i];
if (1 <= px&&px <= h && 1 <= py&&py <= w&&vis[px][py] == 0 && map[px][py] != 'S'&&map[px][py]!='X') {
que.push(make_pair(vis[a.second.first][a.second.second], make_pair(px, py)));
}
}
}
}
cout << ct << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:37:17: error: 'hPos' was not declared in this scope; did you mean 'Pos'?
37 | hPos.pop();
| ^~~~
| Pos
|
s281556232 | p00481 | C++ | #include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<algorithm>
#define INF 1000000
using namespace std;
typedef pair<int,int> P;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
bool map[1000][1000];
int x[10],y[10];
int ans=0;
int h,w,n;
int search(int n){
int d[1000][1000];
std::fill(d,d+sizeof(d),INF);
int sx=x[n],sy=y[n];
int tx=x[n+1],ty=y[n+1];
queue<P> q;
q.push(P(sx,sy));
d[sx][sy]=0;
while(1){
P p=q.front();
q.pop();
sx=p.first,sy=p.second;
if(sx==tx&&sy==ty) return d[tx][ty];
for(int i=0;i<4;i++){
int X=sx+dx[i];
int Y=sy+dy[i];
if(map[X][Y]&&X>=0&&X<h&&Y>=0&&Y<w){
q.push(P(X,Y));
d[X][Y]=d[sx][sy]+1;
}
}
}
}
int main(){
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
char c=getchar();
if(c!='x'){
map[i][j]=true;
if(c=='S'){
x[0]=i,y[0]=j;
}else{
int k=atoi(&c);
x[k]=i;
y[k]=j;
}
}
}
getchar();
}
for(int i=0;i<n;i++){
ans+=search(i);
}
printf("%d\n",ans);
} | In file included from /usr/include/c++/14/deque:62,
from /usr/include/c++/14/queue:62,
from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[1000]; _Tp = int; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21: required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int (*)[1000]; _Tp = int]'
998 | { std::__fill_a1(__first, __last, __value); }
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20: required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[1000]; _Tp = int]'
1029 | std::__fill_a(__first, __last, __value);
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:17:14: required from here
17 | std::fill(d,d+sizeof(d),INF);
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:952:18: error: incompatible types in assignment of 'const int' to 'int [1000]'
952 | *__first = __tmp;
| ~~~~~~~~~^~~~~~~
|
s365823777 | p00481 | C++ | #include <cstdio>
#include <queue>
#define min(x,y) ((x)<(y)?(x):(y))
#define INFI 65535
using namespace std;
typedef pair<int, int> P;
int Strength = 1;
int Maps[1010][1010];
int dist[1010][1010];
int H, W, N;
int hor[] = {1,0,-1,0};
int ver[] = {0,-1,0,1};
int ans;
void clear();
void show();
P bfs(int cheese,P n);
int main(void) {
scanf("%d %d %d\n", &H, &W, &N);
P s,e;
for (int i = 0; i<H; i++) {
for (int j = 0; j<W; j++) {
Maps[i][j] = getchar();
if (Maps[i][j]=='S') {s.first = i; s.second = j;}
if (Maps[i][j]=='0'+N) {e.first = i; e.second = j;}
}
getchar();
}
P tmp;
tmp.first = s.first; tmp.second = s.second;
for (int i = 1; i<=N; i++) {
clear();
tmp = bfs(i, tmp);
}
printf("%d\n", ans);
return 0;
}
P bfs(int cheese,P n) {
P end;
queue<P> que;
que.push(n);
dist[n.first][n.second] = 0;
while (que.size()) {
P top = que.front();
que.pop();
for (int i = 0; i<4; i++) {
int nx = top.first+ver[i], ny = top.second+hor[i];
if (nx>=0 && nx<H && ny>=0 && ny<W && dist[nx][ny]==INFI) {
if (Maps[nx][ny]=='.' || (isdigit(Maps[nx][ny]) && cheese!=Maps[nx][ny]-'0')) {
que.push(P(nx,ny));
dist[nx][ny] = min(dist[nx][ny], dist[top.first][top.second]+1);
} else if (isdigit(Maps[nx][ny]) && cheese==Maps[nx][ny]-'0') {
que.push(P(nx,ny));
dist[nx][ny] = min(dist[nx][ny], dist[top.first][top.second]+1);
end.first = nx; end.second = ny;
break;
}
}
}
}
ans += dist[end.first][end.second];
return end;
}
void clear() {
for (int i = 0; i<H; i++)
for (int j = 0; j<W; j++)
dist[i][j] = INFI;
} | a.cc: In function 'P bfs(int, P)':
a.cc:62:43: error: 'isdigit' was not declared in this scope
62 | if (Maps[nx][ny]=='.' || (isdigit(Maps[nx][ny]) && cheese!=Maps[nx][ny]-'0')) {
| ^~~~~~~
|
s614966602 | p00481 | C++ | #include <iostream>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 0x7f7f7f7f
#define PI acos(-1.0)
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define lowbit(x) (x)&(-x)
#define Mid(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define iabs(x) (x) < 0 ? -(x) : (x)
#define CLR(arr, val) memset(arr, val, sizeof(arr))
using namespace std;
char map[1024][1024];
bool vis[1024][1024];
int cur, h, w;
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
struct node {
int x, y, step;
} sta;
bool check(int x, int y) {
if (x >= 0 && x < h && y >= 0 && y < w && !vis[x][y] && map[x][y] != 'X') return true;
return false;
}
void bfs(node s) {
memset(vis, 0, sizeof(vis));
queue<node> que;
que.push(s);
node next;
while (!que.empty()) {
s = que.front(); que.pop();
next.step = now.step + 1;
for (int i = 0; i < 4; i++) {
next.x = now.x + dir[i][0];
next.y = now.y + dir[i][1];
if (check(next.x, next.y)) {
vis[s.x][s.y] = true;
if (map[next.x][next.y] == cur + '0') {
sta = next;
return ;
}
que.push(next);
}
}
}
}
int main() {
int n;
while (cin >> h >> w >> n) {
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> map[i][j];
if (map[i][j] == 'S') sta.x = i, sta.y = j, map[i][j] = '.';
}
}
sta.step = 0;
for (cur = 1; cur <= n; cur++) {
bfs(sta);
}
cout << sta.step << endl;
}
return 0;
} | a.cc: In function 'void bfs(node)':
a.cc:47:29: error: 'now' was not declared in this scope; did you mean 'pow'?
47 | next.step = now.step + 1;
| ^~~
| pow
|
s573882712 | p00481 | C++ | #include <cstdio>
#include <iostream>
using namespace std;
int ans = 0;
int gh=0, gw=0;
const int max = INT_MAX / 2;
char c[1000][1000];
int d[1000][1000];
int mh[4] = { 1,0,-1,0 };
int mw[4] = { 0,1,0,-1 };
char hijou[9] = { '1','2','3','4','5','6','7','8','9' };
int judge(int h, int w,int g) {
if (c[h][w] ==hijou[g])
{ gh = h;
gw = w;
return d[h][w];
}
for (int i = 0; i < 4; i++) {
int nh = h + mh[i];
int nw = w + mh[i];
if (nh >= 0 && nh < 1000 && nw>=0 && nh < 1000 && d[nh][nw] == max&&c[nh][nw] != 'X') {
d[nh][nw] = d[h][w] + 1;
judge(nh, nw,g);
}
}
}
int main() {
int h, w, n,sh,sw;
for (int i = 0; i < 1000;i++){
for (int j = 0; j < 1000; j++)
{
c[i][j] = 'X';
}
}
cin >> h >> w >> n;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w;j++){
cin >> c[i][j];
if (c[i][j] == 'S') { sh = i; sw = j; }
}
}cout << sh << sw;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 1000; j++) {
for (int k = 0; k < 1000; k++)
d[j][k] = max;
}
d[sh][sw] = 0;
ans+=judge(sh, sw, i);
sh = gh; sw = gw;
}
cout << ans << endl;
} | a.cc:6:17: error: 'INT_MAX' was not declared in this scope
6 | const int max = INT_MAX / 2;
| ^~~~~~~
a.cc:3:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
2 | #include <iostream>
+++ |+#include <climits>
3 | using namespace std;
a.cc: In function 'int judge(int, int, int)':
a.cc:21:80: error: reference to 'max' is ambiguous
21 | if (nh >= 0 && nh < 1000 && nw>=0 && nh < 1000 && d[nh][nw] == max&&c[nh][nw] != 'X') {
| ^~~
In file included from /usr/include/c++/14/string:51,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
a.cc:6:11: note: 'const int max'
6 | const int max = INT_MAX / 2;
| ^~~
a.cc: In function 'int main()':
a.cc:45:43: error: reference to 'max' is ambiguous
45 | d[j][k] = max;
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
a.cc:6:11: note: 'const int max'
6 | const int max = INT_MAX / 2;
| ^~~
a.cc: In function 'int judge(int, int, int)':
a.cc:26:1: warning: control reaches end of non-void function [-Wreturn-type]
26 | }
| ^
|
s686729634 | p00481 | C++ | #include <cstdio>
#include <iostream>
using namespace std;
int ans = 0;
int gh=0, gw=0;
const int max = 500000;
char c[1000][1000];
int d[1000][1000];
int mh[4] = { 1,0,-1,0 };
int mw[4] = { 0,1,0,-1 };
char hijou[9] = { '1','2','3','4','5','6','7','8','9' };
int judge(int h, int w,int g) {
if (c[h][w] ==hijou[g])
{ gh = h;
gw = w;
return d[h][w];
}
for (int i = 0; i < 4; i++) {
int nh = h + mh[i];
int nw = w + mh[i];
if (nh >= 0 && nh < 1000 && nw>=0 && nh < 1000 && d[nh][nw] == max&&c[nh][nw] != 'X') {
d[nh][nw] = d[h][w] + 1;
judge(nh, nw,g);
}
}
}
int main() {
int h, w, n,sh,sw;
for (int i = 0; i < 1000;i++){
for (int j = 0; j < 1000; j++)
{
c[i][j] = 'X';
}
}
cin >> h >> w >> n;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w;j++){
cin >> c[i][j];
if (c[i][j] == 'S') { sh = i; sw = j; }
}
}cout << sh << sw;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 1000; j++) {
for (int k = 0; k < 1000; k++)
d[j][k] = max;
}
d[sh][sw] = 0;
ans+=judge(sh, sw, i);
sh = gh; sw = gw;
}
cout << ans << endl;
} | a.cc: In function 'int judge(int, int, int)':
a.cc:21:80: error: reference to 'max' is ambiguous
21 | if (nh >= 0 && nh < 1000 && nw>=0 && nh < 1000 && d[nh][nw] == max&&c[nh][nw] != 'X') {
| ^~~
In file included from /usr/include/c++/14/string:51,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
a.cc:6:11: note: 'const int max'
6 | const int max = 500000;
| ^~~
a.cc: In function 'int main()':
a.cc:45:43: error: reference to 'max' is ambiguous
45 | d[j][k] = max;
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
a.cc:6:11: note: 'const int max'
6 | const int max = 500000;
| ^~~
a.cc: In function 'int judge(int, int, int)':
a.cc:26:1: warning: control reaches end of non-void function [-Wreturn-type]
26 | }
| ^
|
s943998866 | p00481 | C++ | #include <stdio.h>
#include <queue>
using namespace std;
char map[1000][1000];
bool visited[1000][1000];
int W, H, N;
int startR, startC;
int targetR[10];
int targetC[10];
int dr[4] = {-1, 1, 0, 0};
int dc[4] = {0, 0, -1, 1};
int getMinTime() {
int time = 0;
int curR = startR;
int curC = startC;
for (int i = 0; i < N; ++i) {
memset(visited, false, sizeof(visited));
queue<int> q;
q.push((curR << 16) | curC);
visited[curR][curC] = true;
while (!visited[targetR[i]][targetC[i]]) {
time++;
int count = q.size();
while (count-- > 0) {
int node = q.front();
q.pop();
int r = node >> 16;
int c = node & 0xffff;
for (int j = 0; j < 4; ++j) {
int nr = r + dr[j];
int nc = c + dc[j];
if (nr >= 0 && nr < H && nc >= 0 && nc < W && !visited[nr][nc] && map[nr][nc] != 'X') {
visited[nr][nc] = true;
q.push((nr << 16) | nc);
}
}
}
}
curR = targetR[i];
curC = targetC[i];
}
return time;
}
int main() {
//freopen("Cheese.in", "r", stdin);
while (scanf("%d%d%d", &H, &W, &N) == 3 && W != 0 && H != 0 && N != 0) {
for (int r = 0; r < H; ++r) {
for (int c = 0; c < W; ++c) {
char ch;
do {
ch = getchar();
} while (isspace(ch));
if (ch == 'S') {
startR = r;
startC = c;
} else if (isdigit(ch)) {
int index = ch - '0' - 1;
targetR[index] = r;
targetC[index] = c;
}
map[r][c] = ch;
}
}
int result = getMinTime();
printf("%d\n", result);
}
return 0;
} | a.cc: In function 'int getMinTime()':
a.cc:22:5: error: 'memset' was not declared in this scope
22 | memset(visited, false, sizeof(visited));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 |
a.cc: In function 'int main()':
a.cc:58:18: error: 'isspace' was not declared in this scope
58 | } while (isspace(ch));
| ^~~~~~~
a.cc:62:20: error: 'isdigit' was not declared in this scope
62 | } else if (isdigit(ch)) {
| ^~~~~~~
|
s670537275 | p00481 | C++ | #include <iostream>
#include <vector>
std::vector<std::pair<int, int>> next_list(const int &x, const int &y) {
return { std::make_pair(x + 1, y), std::make_pair(x - 1, y), std::make_pair(x, y + 1), std::make_pair(x, y - 1) };
}
template<typename T>
class Queue {
public:
Queue(const int &n) :vector(n), f(0), b(0) {};
T front() const {
return vector.at(f);
}
T back() const {
return vector.at(b);
}
void pop() {
f = (f + 1) % vector.size();
}
void push(T f) {
vector.at(b) = f;
b = (b + 1) % vector.size();
}
void clear() {
f = 0;
b = 0;
}
private:
std::vector<T> vector;
int f, b;
};
struct Route {
Route(const int &ax = 0, const int &ay = 0, const int &an = 0, const int &atime = 0) :x(ax), y(ay), n(an), time(atime) {};
int x, y, n, time;
bool operator<(const Route &other) const {
return time < other.time;
}
};
int wfs(const std::vector<std::vector<int>> &vector, std::vector<std::vector<int>> &memo, Queue<Route> &queue, const Route &start, const int &goal) {
queue.clear();
queue.push(start);
while (vector.at(queue.front().y).at(queue.front().x) != start.n + 1) {
for (const auto &coord : next_list(queue.front().x, queue.front().y)) {
if (vector.at(coord.second).at(coord.first) >= 0 && memo.at(coord.second).at(coord.first) != start.n) {
memo.at(coord.second).at(coord.first) = start.n;
queue.push(Route(coord.first, coord.second, 0, queue.front().time + 1));
}
}
queue.pop();
}
if (start.n + 1 == goal) {
return queue.front().time;
}
else {
return wfs(vector, memo, queue, Route(queue.front().x, queue.front().y, start.n + 1, queue.front().time), goal);
}
}
int main() {
int h, w, n;
std::cin >> h >> w >> n;
std::vector<std::vector<int>> vector(h + 2, std::vector<int>(w + 2, -1));
Route start(0, 0, 0, 0);
char *arg = new char[w + 2];
for (auto i = 1; i <= h; ++i) {
std::cin >> arg;
for (auto j = 1; j <= w; ++j) {
switch (arg[j - 1]) {
case '.':
vector.at(i).at(j) = 0;
break;
case 'X':
vector.at(i).at(j) = -1;
break;
case 'S':
vector.at(i).at(j) = 0;
start = Route(j, i, 0, 0);
break;
default:
vector.at(i).at(j) = arg[j - 1] - '0';
}
}
}
delete[] arg;
arg = nullptr;
std::cout << wfs(vector, std::vector<std::vector<int>>(h + 2, std::vector<int>(w + 2, -1)), Queue<Route>(h * w * 4), start, n);
return 0;
} | a.cc: In function 'int main()':
a.cc:84:39: error: cannot bind non-const lvalue reference of type 'std::vector<std::vector<int> >&' to an rvalue of type 'std::vector<std::vector<int> >'
84 | std::cout << wfs(vector, std::vector<std::vector<int>>(h + 2, std::vector<int>(w + 2, -1)), Queue<Route>(h * w * 4), start, n);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:38:85: note: initializing argument 2 of 'int wfs(const std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, Queue<Route>&, const Route&, const int&)'
38 | int wfs(const std::vector<std::vector<int>> &vector, std::vector<std::vector<int>> &memo, Queue<Route> &queue, const Route &start, const int &goal) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
|
s953977135 | p00481 | C++ | #include <iostream>
#include <vector>
std::vector<std::pair<int, int>> next_list(const int &x, const int &y) {
return { std::make_pair(x + 1, y), std::make_pair(x - 1, y), std::make_pair(x, y + 1), std::make_pair(x, y - 1) };
}
template<typename T>
class Queue {
public:
Queue(const int &n) :vector(n), f(0), b(0) {};
T front() const {
return vector.at(f);
}
T back() const {
return vector.at(b);
}
void pop() {
f = (f + 1) % vector.size();
}
void push(T f) {
vector.at(b) = f;
b = (b + 1) % vector.size();
}
void clear() {
f = 0;
b = 0;
}
private:
std::vector<T> vector;
int f, b;
};
struct Route {
Route(const int &ax = 0, const int &ay = 0, const int &an = 0, const int &atime = 0) :x(ax), y(ay), n(an), time(atime) {};
int x, y, n, time;
bool operator<(const Route &other) const {
return time < other.time;
}
};
int wfs(const std::vector<std::vector<int>> &vector, std::vector<std::vector<int>> &memo, Queue<Route> &queue, const Route &start, const int &goal) {
queue.clear();
queue.push(start);
while (vector.at(queue.front().y).at(queue.front().x) != start.n + 1) {
for (const auto &coord : next_list(queue.front().x, queue.front().y)) {
if (vector.at(coord.second).at(coord.first) >= 0 && memo.at(coord.second).at(coord.first) != start.n) {
memo.at(coord.second).at(coord.first) = start.n;
queue.push(Route(coord.first, coord.second, 0, queue.front().time + 1));
}
}
queue.pop();
}
if (start.n + 1 == goal) {
return queue.front().time;
}
else {
return wfs(vector, memo, queue, Route(queue.front().x, queue.front().y, start.n + 1, queue.front().time), goal);
}
}
int main() {
int h, w, n;
std::cin >> h >> w >> n;
std::vector<std::vector<int>> vector(h + 2, std::vector<int>(w + 2, -1));
Route start(0, 0, 0, 0);
char *arg = new char[w + 2];
for (auto i = 1; i <= h; ++i) {
std::cin >> arg;
for (auto j = 1; j <= w; ++j) {
switch (arg[j - 1]) {
case '.':
vector.at(i).at(j) = 0;
break;
case 'X':
vector.at(i).at(j) = -1;
break;
case 'S':
vector.at(i).at(j) = 0;
start = Route(j, i, 0, 0);
break;
default:
vector.at(i).at(j) = arg[j - 1] - '0';
}
}
}
delete[] arg;
arg = nullptr;
std::vector<std::vector<int>> memo(h + 2, std::vector<int>(w + 2, -1));
std::cout << wfs(vector, memo, Queue<Route>(h * w * 4), start, n);
return 0;
} | a.cc: In function 'int main()':
a.cc:85:40: error: cannot bind non-const lvalue reference of type 'Queue<Route>&' to an rvalue of type 'Queue<Route>'
85 | std::cout << wfs(vector, memo, Queue<Route>(h * w * 4), start, n);
| ^~~~~~~~~~~~~~~~~~~~~~~
a.cc:38:105: note: initializing argument 3 of 'int wfs(const std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, Queue<Route>&, const Route&, const int&)'
38 | int wfs(const std::vector<std::vector<int>> &vector, std::vector<std::vector<int>> &memo, Queue<Route> &queue, const Route &start, const int &goal) {
| ~~~~~~~~~~~~~~^~~~~
|
s786246493 | p00481 | C++ | #include<cstdio>
#include<algorithm>
#include<queue>
#include <iostream>
#define inf 1000000
using namespace std;
int H,W,N,x0,y0;
char map[1005][1005];int d[1005][1005];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};int d[1005][1005];
typedef pair<int,int>P;
struct position
{
int rx,ry,e;
}xy[9];
bool comp(const position a,const position b)
{
return a.e<b.e;
}
int bfs(int sx,int sy,int gx,int gy)
{
int tx,ty;
queue<P>q;
for(int i=0;i<H;i++)
{
for(int j=0;j<W;j++)
d[i][j]=inf;
}
q.push(P(sx,sy));
d[sx][sy]=0;
while(!q.empty())
{
P p=q.front();
if(p.first==gx&&p.second==gy)
return d[p.first][p.second];
q.pop();
for(int i=0;i<4;i++)
{
tx=p.first+dx[i];
ty=p.second+dy[i];
if(tx>=0&&tx<H&&ty>=0&&ty<W&&map[tx][ty]!='X'&&d[tx][ty]==inf)
{
d[tx][ty]=d[p.first][p.second]+1;
q.push(P(tx,ty));
}
}
}
}
int main(void)
{
while(scanf("%d%d%d",&H,&W,&N)==3)
{
int x1[9],y1[9];
for(int i=0;i<H;i++)
scanf("%s",&map[i]);
int t=0;
for(int i=0;i<H;i++)
{
for(int j=0;j<W;j++)
{
if(map[i][j]=='S')
{
x0=i;
y0=j;
}
if(map[i][j]-'0'>0&&map[i][j]-'0'<=9)
{
xy[t].rx=i;
xy[t].ry=j;
xy[t].e=map[i][j]-'0';
t++;
}
}
}
sort(xy,xy+N,comp);
int ans=bfs(x0,y0,xy[0].rx,xy[0].ry);
for(int i=0;i<N-1;i++)
ans+=bfs(xy[i].rx,xy[i].ry,xy[i+1].rx,xy[i+1].ry);
printf("%d\n",ans);
}
return 0;
} | a.cc:7:14: warning: built-in function 'y0' declared as non-function [-Wbuiltin-declaration-mismatch]
7 | int H,W,N,x0,y0;
| ^~
a.cc:10:26: error: redefinition of 'int d [1005][1005]'
10 | int dy[4]={0,-1,0,1};int d[1005][1005];
| ^
a.cc:8:26: note: 'int d [1005][1005]' previously declared here
8 | char map[1005][1005];int d[1005][1005];
| ^
a.cc: In function 'int bfs(int, int, int, int)':
a.cc:49:1: warning: control reaches end of non-void function [-Wreturn-type]
49 | }
| ^
|
s333046330 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
struct node {
int i;
int j;
char val;
};
int H, W, N;//H(1 <= H <= 1000)、W(1 <= W <=1000)、N(1 <= N <= 9)
char m[1001][1001];
queue<node> q;
bool flag = 0;
int t1 = 0;
char flag_m[1001][1001];
void search(int i, int j, char val)
{
if (flag_m[i][j]<val) {
if (m[i][j] == 'X')
{
return;
}
if (m[i][j] == '.' || m[i][j] != val)
{
q.push({ i,j,val });
//flag_m[i][j] = true;
t1++;
}
if (m[i][j] == val)
{
if (val == ('0' + N))
{
flag = 1;
}
else
{
q.push({ i,j,val + 1 });
//flag_m[i][j] = true;
m[i][j] = '.';
t1++;
}
}
}
return;
}
int main()
{
int si, sj;
scanf("%d %d %d",&H,&W,&N);
for (int i = 1;i <= H; i++)
{
getchar();
for (int j = 1; j <= W; j++)
{
scanf("%c",&(m[i][j]));
if (m[i][j] == 'S')
{
si = i;
sj = j;
}
}
}
//
q.push({si,sj,'1'});
memset(flag_m,'0',sizeof(flag_m));
int t = 1;
int time=0;
while (!q.empty() &&(!flag))
{
time++;
t1 = 0;
while (t-- &&(!flag))
{
node n1 = q.front(); q.pop();
si = n1.i; sj = n1.j;
flag_m[si][sj] = n1.val;
if (si > 1)
{
search(si-1,sj,n1.val);
}
if (si < H)
{
search(si + 1, sj, n1.val);
}
if (sj > 1)
{
search(si, sj-1, n1.val);
}
if (sj < W)
{
search(si, sj+1, n1.val);
}
}
t = t1;
}
printf("%d\n",time);
return 1;
} | a.cc: In function 'void search(int, int, char)':
a.cc:40:50: warning: narrowing conversion of '(((int)val) + 1)' from 'int' to 'char' [-Wnarrowing]
40 | q.push({ i,j,val + 1 });
| ~~~~^~~
a.cc: In function 'int main()':
a.cc:70:9: error: 'memset' was not declared in this scope
70 | memset(flag_m,'0',sizeof(flag_m));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 | using namespace std;
|
s551347416 | p00481 | C++ | // 111.cpp : 定?控制台?用程序的入口点。
//
#include "stdafx.h"
#include<stdio.h>
#include <queue>
using namespace std;
#define N 1001
int cols,rows,n;
char a[N][N];
bool visited[N][N] = {0};
int minTime;
int direction[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
struct Point{
int x;
int y;
};
bool isInMap(Point p){
if(p.x < 0 || p.x >= rows)return 0;
if(p.y < 0 || p.y >= cols)return 0;
else return 1;
}
int bfs(Point startP,Point endP){
//printf("strat x = %d y= %d\n",startP.x,startP.y);
//printf("end x = %d y = %d\n",endP.x,endP.y);
int count = 1;
queue<Point> point;
int time =0;
point.push(startP);
visited[startP.x][startP.y] = 1;
while(point.size()){
int count1 = count;
//printf("count1 = %d\n",count1);
count = 0;
time++;
for(int i = 0; i < count1; i++)
{
//printf("time = %d",time);
Point cur = point.front();
point.pop();
for(int j = 0 ; j < 4; j++)
{
Point temp;
temp.x = cur.x + direction[j][0];
temp.y = cur.y + direction[j][1];
if(isInMap(temp) && a[temp.x][temp.y] != 'X' && visited[temp.x][temp.y] == 0)
{
point.push(temp);
visited[temp.x][temp.y] = 1;
count++;
}
if(temp.x == endP.x && temp.y == endP.y)return time;
}
}
}
}
int main(){
Point startP,endP;
int totalStep = 0;
scanf("%d%d%d",&rows,&cols,&n);
getchar();
for(int i = 0; i < rows; i++)
{
for(int j = 0 ; j < cols; j++)
{
scanf("%c",&a[i][j]);
if(a[i][j] == 'S'){a[i][j] = '0';}
}
getchar();
}
minTime = 100000;
for(int k = 0; k < n; k++)
{
for(int i = 0; i < rows; i++)
for(int j = 0; j <cols; j++)
{
if((int)a[i][j] == (k+48)){startP.x = i;startP.y = j;}
if((int)a[i][j] == (k+1+48)){endP.x = i;endP.y = j;}
visited[i][j] = 0;
}
totalStep += bfs(startP,endP);
}
printf("%d",totalStep);
} | a.cc:4:10: fatal error: stdafx.h: No such file or directory
4 | #include "stdafx.h"
| ^~~~~~~~~~
compilation terminated.
|
s236384761 | p00481 | C++ | #include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int H, W,N;
int time = 0;
int flag = 0; // ?志是否?束
int flagt = 0; // ??一个?点有几个相??点
char SearchMap[1001][1001];
int SearchFlag[1001][1001] = {0};
struct node
{
int IndexX;
int IndexY;
int value;
};
queue<node> q;
void FoundTheNext(int x,int y,int val)
{
if (SearchFlag[x][y] < val)
{
if (SearchMap[x][y] == 'X')
return;
if (SearchMap[x][y] - '0' == val)
{
if (val == N)
flag = 1;
else
{
q.push({ x,y,val + 1 });
SearchMap[x][y] = '.';
flagt++;
}
}
if (SearchMap[x][y] == '.'|| SearchMap[x][y]-'0'!=val)
{
q.push({ x,y,val});
flagt++;
}
return;
}
}
int main()
{
scanf("%d %d %d",&H,&W,&N);
int starti = 0, startj = 0; // ???始的位置
for (int i = 1; i <= H; i++)
{
getchar();
for (int j = 1; j <= W; j++)
{
scanf("%c", &(SearchMap[i][j]));
if (SearchMap[i][j] == 'S')
{
starti = i;
startj = j;
}
}
}
q.push({starti,startj,1}); // ?始体力?1
int resultTime = 0; // ??走的?数、??
int t1 = 1;
while (!q.empty()&&flag==0)
{
resultTime++;
flagt = 0;
while (t1--&&flag == 0)
{
node nodeflag = q.front();
int x = nodeflag.IndexX, y = nodeflag.IndexY, value = nodeflag.value;
q.pop();
SearchFlag[x][y] = value; // ?置??数据的?
if (x > 1)
FoundTheNext(x - 1, y, value);
if (x < H)
FoundTheNext(x + 1, y, value);
if (y > 1)
FoundTheNext(x, y - 1, value);
if (y < W)
FoundTheNext(x, y + 1, value);
}
t1 = flagt;
}
if (flag == 1)
printf("%d",resultTime);
return 1;
} | a.cc:7:5: error: 'int time' redeclared as different kind of entity
7 | int time = 0;
| ^~~~
In file included from /usr/include/pthread.h:23,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
from /usr/include/c++/14/ext/atomicity.h:35,
from /usr/include/c++/14/bits/ios_base.h:39,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
76 | extern time_t time (time_t *__timer) __THROW;
| ^~~~
|
s192241818 | p00481 | C++ | #include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int H, W,N;
int flag = 0; // ?志是否?束
int flagt = 0; // ??一个?点有几个相??点
char SearchMap[1001][1001];
int SearchFlag[1001][1001] = {0};
struct node
{
int IndexX;
int IndexY;
int value;
};
queue<node> q;
void FoundTheNext(int x,int y,int val)
{
if (SearchFlag[x][y] < val)
{
if (SearchMap[x][y] == 'X')
return;
if (SearchMap[x][y] - '0' == val)
{
if (val == N)
flag = 1;
else
{
q.push({ x,y,val + 1 });
SearchMap[x][y] = '.';
flagt++;
}
}
if (SearchMap[x][y] == '.'|| SearchMap[x][y]-'0'!=val)
{
q.push({ x,y,val});
flagt++;
}
return;
}
}
int main()
{
scanf_s("%d %d %d",&H,&W,&N);
int starti = 0, startj = 0; // ???始的位置
for (int i = 1; i <= H; i++)
{
getchar();
for (int j = 1; j <= W; j++)
{
scanf_s("%c", &(SearchMap[i][j]));
if (SearchMap[i][j] == 'S')
{
starti = i;
startj = j;
}
}
}
q.push({starti,startj,1}); // ?始体力?1
int resultTime = 0; // ??走的?数、??
int t1 = 1;
while (!q.empty()&&flag==0)
{
resultTime++;
flagt = 0;
while (t1--&&flag == 0)
{
node nodeflag = q.front();
int x = nodeflag.IndexX, y = nodeflag.IndexY, value = nodeflag.value;
q.pop();
SearchFlag[x][y] = value; // ?置??数据的?
if (x > 1)
FoundTheNext(x - 1, y, value);
if (x < H)
FoundTheNext(x + 1, y, value);
if (y > 1)
FoundTheNext(x, y - 1, value);
if (y < W)
FoundTheNext(x, y + 1, value);
}
t1 = flagt;
}
if (flag == 1)
printf_s("%d\n",resultTime);
system("pause");
return 1;
} | a.cc: In function 'int main()':
a.cc:50:9: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
50 | scanf_s("%d %d %d",&H,&W,&N);
| ^~~~~~~
| scanf
a.cc:100:17: error: 'printf_s' was not declared in this scope; did you mean 'printf'?
100 | printf_s("%d\n",resultTime);
| ^~~~~~~~
| printf
|
s373136420 | p00481 | C++ | #include <iostream>
#include <stdio.h>
#include <cstring>
#include <queue>
using namespace std;
char ma[1005][1005];int vis[1005][1005];
int w,h,n;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
struct node
{
int x,y,time;
};
node start;
void bfs(char ed)
{
queue<node> que;
que.push(start);
vis[start.x][start.y]=1;
while(!que.empty())
{
node no=que.front();
que.pop();
for(int i=0;i<4;i++)
{
int x=no.x+dx[i];
int y=no.y+dy[i];
if(vis[x][y]||x>=h||x<0||y>=w||y<0||ma[x][y]=='X')
continue;
if(ma[x][y]==ed)
{
start.x=x;
start.y=y;
start.time=no.time+1;
return ;
}
vis[x][y]=1;
node no1;
no1.x=x;no1.y=y;no1.time=no.time+1;
que.push(no1);
}
}
}
int main()
{
while(~scanf("%d %d %d\n", & h, & w, & n))
{
for(int i=0;i<h;i++)
{
//scanf("%s",&ma[i]);
gets(ma[i]);
for(int j=0;j<w;j++)
if(ma[i][j]=='S')
{
start.x=i;
start.y=j;
start.time=0;
}
}
for(int i=0;i<n;i++)
{
memset(vis,0,sizeof(vis));
bfs(i+'1');
}
printf("%d\n",start.time);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:56:13: error: 'gets' was not declared in this scope; did you mean 'getw'?
56 | gets(ma[i]);
| ^~~~
| getw
|
s963229227 | p00481 | C++ | #include<iostream>
#include<deque>
using namespace std;
int H, W, N;
char mapT[1000][1000];
int vis[1000][1000];
int temp_x = 0, temp_y;
char temp;
int final_min_route = 0;
int dir[4][2] = { {-1,0},{0,1},{1,0},{0,-1} };
struct location {
int x, y, route;
};
location findSmallRouteBFS(int x, int y, char factory) {
memset(vis, 0, sizeof(vis));
deque<location> que;
location temp = { x,y,0 };
que.push_back(temp);
vis[x][y] = 1;
while (!que.empty()) {
location st = que.front();
que.pop_front();
if (mapT[st.x][st.y] == factory) {
return st;
}
for (int i = 0; i < 4; ++i) {
int t_x = st.x + dir[i][0];
int t_y = st.y + dir[i][1];
if (t_x < 0 || t_x >= H || t_y < 0 || t_y >= W || mapT[t_x][t_y] == 'X') {
continue;
}
location temp = { t_x,t_y,st.route + 1 };
if (!vis[t_x][t_y]) {
vis[t_x][t_y] = 1;
que.push_back(temp);
}
}
}
}
int main() {
cin >> H >> W >> N;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; ++j) {
cin >> temp;
mapT[i][j] = temp;
if (temp == 'S') {
mapT[i][j] = '0';
temp_x = i;
temp_y = j;
}
}
}
for (int factory = 1; factory != N + 1; ++factory) {
location lo = findSmallRouteBFS(temp_x, temp_y, mapT[temp_x][temp_y] + 1);
temp_x = lo.x;
temp_y = lo.y;
final_min_route += lo.route;
}
cout << final_min_route << endl;
//system("pause");
return 0;
} | a.cc: In function 'location findSmallRouteBFS(int, int, char)':
a.cc:19:9: error: 'memset' was not declared in this scope
19 | memset(vis, 0, sizeof(vis));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<deque>
+++ |+#include <cstring>
3 |
a.cc:44:1: warning: control reaches end of non-void function [-Wreturn-type]
44 | }
| ^
|
s537688096 | p00481 | C++ | #include<iostream>
#include<deque>
using namespace std;
int H, W, N;
char mapT[1000][1000];
int vis[1000][1000];
int temp_x = 0, temp_y;
char temp;
int final_min_route = 0;
int dir[4][2] = { {-1,0},{0,1},{1,0},{0,-1} };
struct location {
int x, y, route;
};
location findSmallRouteBFS(int x, int y, char factory) {
memset(vis, 0, sizeof(vis));
deque<location> que;
location temp = { x,y,0 };
que.push_back(temp);
vis[x][y] = 1;
while (!que.empty()) {
location st = que.front();
que.pop_front();
if (mapT[st.x][st.y] == factory) {
return st;
}
for (int i = 0; i < 4; ++i) {
int t_x = st.x + dir[i][0];
int t_y = st.y + dir[i][1];
if (t_x < 0 || t_x >= H || t_y < 0 || t_y >= W || mapT[t_x][t_y] == 'X') {
continue;
}
location temp = { t_x,t_y,st.route + 1 };
if (!vis[t_x][t_y]) {
vis[t_x][t_y] = 1;
que.push_back(temp);
}
}
}
}
int main() {
cin >> H >> W >> N;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; ++j) {
cin >> temp;
mapT[i][j] = temp;
if (temp == 'S') {
mapT[i][j] = '0';
temp_x = i;
temp_y = j;
}
}
}
for (int factory = 1; factory != N + 1; ++factory) {
location lo = findSmallRouteBFS(temp_x, temp_y, mapT[temp_x][temp_y] + 1);
temp_x = lo.x;
temp_y = lo.y;
final_min_route += lo.route;
}
cout << final_min_route << endl;
//system("pause");
return 0;
} | a.cc: In function 'location findSmallRouteBFS(int, int, char)':
a.cc:19:9: error: 'memset' was not declared in this scope
19 | memset(vis, 0, sizeof(vis));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<deque>
+++ |+#include <cstring>
3 |
a.cc:44:1: warning: control reaches end of non-void function [-Wreturn-type]
44 | }
| ^
|
s402272898 | p00481 | C++ | #include <iostream>
#include <queue>
const int MAX_H = 1000;
const int MAX_W = 1000;
const int a = 100000000;
using namespace std;
typedef pair<int, int> P;
int H = 0, W = 0, N = 0;
int food[11][2];
char cheese[MAX_H][MAX_W] = {0};
int r[MAX_H][MAX_W];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int search(int &sx, int &sy, int &ex, int &ey)
{
P p;
queue<P> que;
for(int i=0; i<H; i++)
{
for(int j=0; j<W; j++)
{
r[i][j] = a;
}
}
que.push(P(sx,sy));
r[sx][sy] = 0;
while(que.size())
{
p = que.front();
que.pop();
if(p.first == ex && p.second == ey)
break;
for(int i=0; i<4; i++)
{
int xn = p.first + dx[i];
int yn = p.second + dy[i];
if(xn >= 0 && xn < H && yn >= 0 && yn < W && cheese[xn][yn]!='X' && r[xn][yn] == a )
{
que.push(P(xn,yn));
r[xn][yn] = r[p.first][p.second] + 1;
}
}
}
return r[ex][ey];
}
int main()
{
int dis = 0;
cin >> H >> W >> N;
for(int i=0; i<H; i++)
{
for(int j=0; j<W; j++)
{
cin >> cheese[i][j];
if(cheese[i][j] == 'S')
{
food[0][0] = i;
food[0][1] = j;
cheese[i][j] = '.';
}
if(cheese[i][j]>48&&cheese[i][j]<58)
{
int num = cheese[i][j] - 48;
factor[num][0] = i;
factor[num][1] = j;
}
}
}
for(int i=0; i<N; i++)
{
dis += search(food[i][0], food[i][1], food[i+1][0], food[i+1][1]);
}
cout << dis << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:79:14: error: 'factor' was not declared in this scope
79 | factor[num][0] = i;
| ^~~~~~
|
s820264822 | p00481 | C++ | #include<stack>
#include<queue>
#include "StdAfx.h"
const int MAX_H = 1000;
const int MAX_W = 1000;
const int a = 100000000;
using namespace std;
typedef pair<int, int> P;
int H = 0, W = 0, N = 0;
int food[11][2];
char cheese[MAX_H][MAX_W] = {0};
int r[MAX_H][MAX_W];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int search(int &sx, int &sy, int &ex, int &ey)
{
P p;
queue<P> que;
for(int i=0; i<H; i++)
{
for(int j=0; j<W; j++)
{
r[i][j] = a;
}
}
que.push(P(sx,sy));
r[sx][sy] = 0;
while(que.size())
{
p = que.front();
que.pop();
if(p.first == ex && p.second == ey)
break;
for(int i=0; i<4; i++)
{
int xn = p.first + dx[i];
int yn = p.second + dy[i];
if(xn >= 0 && xn < H && yn >= 0 && yn < W && cheese[xn][yn]!='X' && r[xn][yn] == a )
{
que.push(P(xn,yn));
r[xn][yn] = r[p.first][p.second] + 1;
}
}
}
return r[ex][ey];
}
int main()
{
int dis = 0;
cin >> H >> W >> N;
for(int i=0; i<H; i++)
{
for(int j=0; j<W; j++)
{
cin >> cheese[i][j];
if(cheese[i][j] == 'S')
{
food[0][0] = i;
food[0][1] = j;
cheese[i][j] = '.';
}
if(cheese[i][j]>48&&cheese[i][j]<58)
{
int num = cheese[i][j] - 48;
factor[num][0] = i;
factor[num][1] = j;
}
}
}
for(int i=0; i<N; i++)
{
dis += search(food[i][0], food[i][1], food[i+1][0], food[i+1][1]);
}
cout << dis << endl;
return 0;
} | a.cc:3:10: fatal error: StdAfx.h: No such file or directory
3 | #include "StdAfx.h"
| ^~~~~~~~~~
compilation terminated.
|
s574594769 | p00481 | C++ | #include "StdAfx.h"
#include <iostream>
#include<stack>
#include<queue>
#include<string>
#include <math.h>
using namespace std;
const int MAX_H = 1000;
const int MAX_W = 1000;
const int a = 100000000;
typedef pair<int, int> P;
int H = 0, W = 0, N = 0;
int food[11][2];
char cheese[MAX_H][MAX_W] = {0};
int r[MAX_H][MAX_W];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int search(int &sx, int &sy, int &ex, int &ey)
{
P p;
queue<P> que;
for(int i=0; i<H; i++)
{
for(int j=0; j<W; j++)
{
r[i][j] = a;
}
}
que.push(P(sx,sy));
r[sx][sy] = 0;
while(que.size())
{
p = que.front();
que.pop();
if(p.first == ex && p.second == ey)
break;
for(int i=0; i<4; i++)
{
int xn = p.first + dx[i];
int yn = p.second + dy[i];
if(xn >= 0 && xn < H && yn >= 0 && yn < W && cheese[xn][yn]!='X' && r[xn][yn] == a )
{
que.push(P(xn,yn));
r[xn][yn] = r[p.first][p.second] + 1;
}
}
}
return r[ex][ey];
}
int main()
{
int dis = 0;
cin >> H >> W >> N;
for(int i=0; i<H; i++)
{
for(int j=0; j<W; j++)
{
cin >> cheese[i][j];
if(cheese[i][j] == 'S')
{
food[0][0] = i;
food[0][1] = j;
cheese[i][j] = '.';
}
if(cheese[i][j]>48&&cheese[i][j]<58)
{
int num = cheese[i][j] - 48;
food[num][0] = i;
food[num][1] = j;
}
}
}
for(int i=0; i<N; i++)
{
dis += search(food[i][0], food[i][1], food[i+1][0], food[i+1][1]);
}
cout << dis << endl;
return 0;
} | a.cc:1:10: fatal error: StdAfx.h: No such file or directory
1 | #include "StdAfx.h"
| ^~~~~~~~~~
compilation terminated.
|
s837791464 | p00481 | C++ | #include<iostream>
#include<vector>
using namespace std;
char ma[1001][1001];
bool visited[1001][1001];
int h,w,n;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int sx,sy;
vector<pair<int,int> >vec(10);
int bfs(int x,int y,int d){
if(ma[y][x]-'0'==d){
return 0;
}
visited[y][x]=1;
int ret=100000000;
for(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+dy[i];
if(nx>=0&&nx<w&&ny>=0&&ny<h&&ma[ny][nx]!='X'&&!visited[ny][nx]){
ret=min(ret,bfs(nx,ny,d));
}
}
visited[y][x]=0;
return ret+1;
}
int main(){
memset(visited,0,sizeof(visited));
cin>>h>>w>>n;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>ma[i][j];
if(ma[i][j]>'0'&&ma[i][j]<='9'){
vec[ma[i][j]-'0']=make_pair(i, j);
}
if(ma[i][j]=='S'){
vec[0]=make_pair(i, j);
}
}
}
int c=0;
for(int i=1;i<=n;i++){
c+=bfs(vec[i-1].second,vec[i-1].first,i);
}
cout<<c<<endl;
} | a.cc: In function 'int main()':
a.cc:31:5: error: 'memset' was not declared in this scope
31 | memset(visited,0,sizeof(visited));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<vector>
+++ |+#include <cstring>
3 | using namespace std;
|
s203398177 | p00481 | C++ | from : http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1811250#1
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<(#x)<<": "<<(x)<<endl
int nowS = 0;
int x, y, n;
int mp[1000][1000] = {};
int k[4] = {1, -1, 0, 0};
int h[4] = {0, 0, 1, -1};
int cx[9] = {};
int cy[9] = {};
queue<int> bufX, bufY, bufD;
bool search(int xx, int yy, int dd) {
bufX.pop();
bufY.pop();
bufD.pop();
for (int i = 0; i < 4; i++) {
int nx = xx+k[i];
int ny = yy+h[i];
if (nx < 0 || nx >= x || ny < 0 || ny >= y)//?????????
continue;
if (mp[ny][nx] == -1) {//?????
continue;
}
if (cx[nowS] == nx && cy[nowS] == ny) {//??????
nowS++;
while (!bufX.empty()) {
bufX.pop();
bufY.pop();
bufD.pop();
}
if (nowS == n) {//?????????????????????
cout << dd + 1 << endl;
return true;
}
else {//
bufX.push(nx);
bufY.push(ny);
bufD.push(dd + 1);
mp[ny][nx] = nowS + 1;
}
return false;
}
if(mp[ny][nx] >= 0 && mp[ny][nx] < nowS + 1){
bufX.push(nx);
bufY.push(ny);
bufD.push(dd + 1);
mp[ny][nx] = nowS + 1;
}
}
return false;
}
int main() {
int ch = 0;
cin >> y >> x >> n;
for (int i = 0; i < y; i++) {//??\???
char c[1001];
cin >> c;
for (int j = 0; j < x; j++) {
if(c[j] == 'X')
mp[i][j] = -1;
else if(c[j] == 'S'){
bufX.push(j);
bufY.push(i);
bufD.push(0);
mp[i][j] = 1;
}
else {
mp[i][j] = 0;
}
if (c[j] >= 48 && c[j] <= 57) {
int m;
m = c[j] - 49;
cx[m] = j;
cy[m] = i;
ch++;
}
}
}
while(!search(bufX.front(), bufY.front(), bufD.front())){}//???????????????§?????????
return 0;
} | a.cc:1:6: error: found ':' in nested-name-specifier, expected '::'
1 | from : http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1811250#1
| ^
| ::
a.cc:1:1: error: 'from' does not name a type
1 | from : http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1811250#1
| ^~~~
In file included from /usr/include/c++/14/iosfwd:42,
from /usr/include/c++/14/ios:40,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:3:
/usr/include/c++/14/bits/postypes.h:68:11: error: 'ptrdiff_t' does not name a type
68 | typedef ptrdiff_t streamsize; // Signed integral type
| ^~~~~~~~~
/usr/include/c++/14/bits/postypes.h:41:1: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
40 | #include <cwchar> // For mbstate_t
+++ |+#include <cstddef>
41 |
In file included from /usr/include/c++/14/bits/exception_ptr.h:38,
from /usr/include/c++/14/exception:166,
from /usr/include/c++/14/ios:41:
/usr/include/c++/14/new:131:26: error: declaration of 'operator new' as non-function
131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~~~
/usr/include/c++/14/new:131:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~
In file included from /usr/include/wchar.h:35,
from /usr/include/c++/14/cwchar:44,
from /usr/include/c++/14/bits/postypes.h:40:
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:132:41: error: attributes after parenthesized initializer ignored [-fpermissive]
132 | __attribute__((__externally_visible__));
| ^
/usr/include/c++/14/new:133:26: error: declaration of 'operator new []' as non-function
133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~~~
/usr/include/c++/14/new:133:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:134:41: error: attributes after parenthesized initializer ignored [-fpermissive]
134 | __attribute__((__externally_visible__));
| ^
/usr/include/c++/14/new:140:29: error: 'std::size_t' has not been declared
140 | void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
| ^~~
/usr/include/c++/14/new:142:31: error: 'std::size_t' has not been declared
142 | void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
| ^~~
/usr/include/c++/14/new:145:26: error: declaration of 'operator new' as non-function
145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/14/new:145:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:145:52: error: expected primary-expression before 'const'
145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~
/usr/include/c++/14/new:147:26: error: declaration of 'operator new []' as non-function
147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/14/new:147:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:147:54: error: expected primary-expression before 'const'
147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~
/usr/include/c++/14/new:154:26: error: declaration of 'operator new' as non-function
154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
| ^~~~~~~~
/usr/include/c++/14/new:154:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:154:68: error: expected primary-expression before ')' token
154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
| ^
/usr/include/c++/14/new:155:73: error: attributes after parenthesized initializer ignored [-fpermissive]
155 | __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
| ^
/usr/include/c++/14/new:156:26: error: declaration of 'operator new' as non-function
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~~~
/usr/include/c++/14/new:156:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:156:68: error: expected primary-expression before ',' token
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^
/usr/include/c++/14/new:156:70: error: expected primary-expression before 'const'
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~
/usr/include/c++/14/new:162:26: error: declaration of 'operator new []' as non-function
162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
| ^~~~~~~~
/usr/include/c++/14/new:162:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:162:70: error: expected primary-expression before ')' token
162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
| ^
/usr/include/c++/14/new:163:73: error: attributes after parenthesized initializer ignored [-fpermissive]
163 | __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
| ^
/usr/include/c++/14/new:164:26: error: declaration of 'operator new []' as non-function
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~~~
/usr/include/c++/14/new:164:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:164:70: error: expected primary-expression before ',' token
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^
/usr/include/c++/14/new:164:72: error: expected primary-expression before 'const'
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~
/usr/include/c++/14/new:171:29: error: 'std::size_t' has not been declared
171 | void operator delete(void*, std::size_t, std::align_val_t)
| ^~~
/usr/include/c++/14/new:173:31: error: 'std::size_t' has not been declared
173 | void operator delete[](void*, std::size_t, std::align_val_t)
| ^~~
/usr/include/c++/14/new:179:33: error: declaration of 'operator new' as non-function
179 | _GLIBCXX_NODISCARD inline void* |
s709035975 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <limits>
#include <queue>
using namespace std;
const int MAX_W = 1000;
const int MAX_H = 1000;
const int MAX_N = 9;
typedef pair<int, int> P;
int H,W,N;
char field[MAX_H][MAX_W];
int dist[MAX_H][MAX_W];
queue<P> que;
//using limits = std::numeric_limits<int>;
int limits = 99999;
void getStatus(int y, int x, int min_dist){
for(int i = 0; i< H; i++) {
for (int j = 0; j < W; j++) {
if( i == y && j == x){
cout << "$";
}else {
cout << field[i][j];
}
}
cout << endl;
}
cout << "-------------min_dist:" << min_dist << endl;
}
int bfs(int goal){
int gx,gy;
while( que.size()){
P p = que.front(); que.pop();
int a = p.first;
int b = p.second;
if( atoi(&field[p.first][p.second]) == goal ) { gy = p.first; gx = p.second; break; }
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
for(int i=0; i< 4; i++){
int ny = p.first + dy[i],
nx = p.second+ dx[i];
if( 0 <= nx
&& nx < W
&& 0<= ny
&& ny < H
&& field[ny][nx] != 'X'
&& dist[ny][nx] == limits::infinity() ){
que.push(P(ny,nx) );
dist[ny][nx] = dist[p.first][p.second] + 1;
}
}
// getStatus(p.first,p.second,dist[p.first][p.second]);
}
return dist[gy][gx];
}
void init_dist(){
for(int i=0; i< H; i++){
for(int j=0; j<W; j++){
dist[i][j] = limits::infinity();
}
}
queue<P>().swap(que);
}
void solve(){
int sum = 0;
for(int i = 0; i< H; i++){
for(int j = 0; j< W; j++){
if( field[i][j] == 'S'){
init_dist();
que.push(P(i,j));
dist[i][j] = 0;
sum += bfs(1);
}
for(int k = 1; k<N; k++){
if( atoi(&field[i][j]) == k ) {
init_dist();
que.push(P(i,j));
dist[i][j] = 0;
sum+=bfs(k+1);
}
}
}
}
cout << sum << endl;
}
int main() {
while(1){
string line;
cin >> H >> W >> N;cin.ignore();
if( H == 0 && W == 0 ){
break;
}
for(int i = 0; i< H; i++){
getline(cin,line);
for(int j = 0; j< W; j++){
field[i][j] = line[j];
}
}
solve();
}
return 0;
}
/*
10 10 9
.X...X.S.X
6..5X..X1X
...XXXX..X
X..9X...X.
8.X2X..X3X
...XX.X4..
XX....7X..
X..X..XX..
X...X.XX..
..X.......
*/ | a.cc: In function 'int bfs(int)':
a.cc:62:37: error: 'limits' is not a class, namespace, or enumeration
62 | && dist[ny][nx] == limits::infinity() ){
| ^~~~~~
a.cc: In function 'void init_dist()':
a.cc:79:26: error: 'limits' is not a class, namespace, or enumeration
79 | dist[i][j] = limits::infinity();
| ^~~~~~
|
s912874962 | p00481 | C++ | #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define pii pair<int, int>
#define ll long long
using namespace std;
#define MAX 10
#define SIZE 1000
#define INF 1<<30
int H, W, N;
char sec[SIZE][SIZE+1];
int time = INF;
int all_time = 0;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
int facy[10] = {};
int facx[10] = {};
struct state {
int sy, sx, gy, gx, cnt;
state() {}
state(int _sy, int _sx, int _gy, int _gx, int _cnt) :
sy(_sy), sx(_sx), gy(_gy), gx(_gx), cnt(_cnt) {}
};
queue<state> que;
void bfs()
{
int **tsec = new int*[SIZE];
rep(i,0,SIZE) tsec[i] = new int[SIZE+1];
rep(i,0,H) rep(j,0,W) tsec[i][j] = (int)sec[i][j];
//rep(i,0,H) { rep(j,0,W) cout << tsec[i][j] << " "; cout << endl;}
while (!que.empty()) {
state ts = que.front(); que.pop();
//printf("sy=%d sx=%d gy=%d gx=%d cnt=%d\n",ts.sy,ts.sx,ts.gy,ts.gx,ts.cnt);
if (ts.cnt > time) return;
if (ts.sy == ts.gy && ts.sx == ts.gx) time = min(time, ts.cnt);
tsec[ts.sy][ts.sx] = ts.cnt;
rep(i, 0, 4) {
int ny = ts.sy + dy[i];
int nx = ts.sx + dx[i];
if (ny < 0 || ny >= H) continue;
if (nx < 0 || nx >= W) continue;
if (sec[ny][nx] == 'X') continue;
if (tsec[ny][nx] < ts.cnt) continue;
state ns(ny, nx, ts.gy, ts.gx, ts.cnt + 1);
que.push(ns);
}
//rep(i,0,H) { rep(j,0,W) cout << tsec[i][j] << " "; cout << endl;}
}
rep(i,0,SIZE) delete[] tsec[i];
delete[] tsec;
}
void solve()
{
// rep(i,0,N+1) printf("%d y=%d x=%d\n",i,facy[i],facx[i]);
rep(i,0,N) {
time = INF;
while(!que.empty()) que.pop();
state s(facy[i], facx[i], facy[i+1], facx[i+1], 0);
que.push(s);
//printf("\n bfs start !! \n");
bfs();
all_time += time;
}
cout << all_time << endl;
}
void input()
{
cin >> H >> W >> N;
rep(i,0,H) {
rep(j,0,W) {
cin >> sec[i][j];
if (sec[i][j] == 'S') { facy[0] = i; facx[0] = j; }
if (sec[i][j] >= 49 && 57 >= sec[i][j]) {
facy[sec[i][j]-48] = i;
facx[sec[i][j]-48] = j;
}
}
}
solve();
}
int main(void)
{
input();
return 0;
} | a.cc:20:5: error: 'int time' redeclared as different kind of entity
20 | int time = INF;
| ^~~~
In file included from /usr/include/pthread.h:23,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
from /usr/include/c++/14/ext/atomicity.h:35,
from /usr/include/c++/14/bits/ios_base.h:39,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
76 | extern time_t time (time_t *__timer) __THROW;
| ^~~~
a.cc: In function 'void bfs()':
a.cc:45:28: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
45 | if (ts.cnt > time) return;
| ~~~~~~~^~~~~~
a.cc:46:65: error: no matching function for call to 'min(time_t (&)(time_t*) noexcept, int&)'
46 | if (ts.sy == ts.gy && ts.sx == ts.gx) time = min(time, ts.cnt);
| ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:46:65: note: deduced conflicting types for parameter 'const _Tp' ('long int(long int*) noexcept' and 'int')
46 | if (ts.sy == ts.gy && ts.sx == ts.gx) time = min(time, ts.cnt);
| ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
5686 | min(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
5696 | min(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed:
a.cc:46:65: note: mismatched types 'std::initializer_list<_Tp>' and 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'}
46 | if (ts.sy == ts.gy && ts.sx == ts.gx) time = min(time, ts.cnt);
| ~~~^~~~~~~~~~~~~~
a.cc: In function 'void solve()':
a.cc:71:22: error: assignment of function 'time_t time(time_t*)'
71 | time = INF;
| ^
a.cc:77:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
77 | all_time += time;
| ~~~~~~~~~^~~~~~~
a.cc:77:26: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
77 | all_time += time;
| ~~~~~~~~~^~~~~~~
| |
| time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
|
s692178457 | p00481 | C++ | #include<stdio.h>
#include<iostream>
#include<string.h>
#include<queue>
using namespace std;
struct OZAWA
{
int x;
int y;
int c;
};
int Flag[1000][1000];
char MAP[1000][1000];
queue<OZAWA> Q;
int main(void)
{
int H,W,N,Nc=0,X[10],Y[10];
OZAWA ba,v;
int mv[4][2]={{0,-1},{1,0},{0,1},{-1,0}};
char Cheese[10] ={'1','2','3','4','5','6','7','8','9'};
memset(MAP,'X',sizeof(MAP));
memset(Flag,0,sizeof(Flag));
scanf("%d %d %d",&H,&W,&N);
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
//printf("%d %d ",i,j);
cin >> MAP[i][j];
//printf("Q");
if(MAP[i][j] == 'S'){
ba.x = j;
ba.y = i;
ba.c = 0;
Flag[i][j] = 1;
Q.push(ba);
//printf("Sin\n");
}
for(int ii=0;ii<9;ii++){
if(MAP[i][j] == Cheese[ii]){
X[ii] = j;
Y[ii] = i;
//printf("\n@@@\n");
}
}
}
}
//printf("S %d %d\n",ba.x,ba.y);
//for(int ii=0;ii<2;ii++)
//printf("%d %d\n",X[0],Y[0]);
while(!Q.empty()){
//printf("QA\n");
ba = Q.front();
Q.pop();
if(ba.x==X[Nc] && ba.y==Y[Nc]){
//printf("OZA");
Nc++;
memset(Flag,0,sizeof(Flag));
while(!Q.empty()){
Q.pop();
}
Q.push(ba);
}
//printf("aaa\n");
if(Nc == N) break;
for(int i=0;i<4;i++){
if(MAP[ba.y+mv[i][1]][ba.x+mv[i][0]]!='X' && Flag[ba.y+mv[i][1]][ba.x+mv[i][0]]==0 && (ba.x+mv[i][0])>=0&&(ba.x+mv[i][0])<W&&(ba.y+mv[i][1])>=0&&(ba.y+mv[i][1])<H){
v.x=ba.x+mv[i][0];
v.y=ba.y+mv[i][1];
v.c=ba.c+1;
Q.push(v);
Flag[v.y][v.x] = 1;
//printf("%d %d\n",v.x,v.y);
}
}
}
cout <<ba.c<<endl
return 0;
} | a.cc: In function 'int main()':
a.cc:77:26: error: expected ';' before 'return'
77 | cout <<ba.c<<endl
| ^
| ;
78 | return 0;
| ~~~~~~
|
s944784619 | p00481 | C++ | #include<cstdio.h>
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
struct PP{
int x;
int
int Z;
int c;
};
char s[1002][1002],C[11]={"0123456789"};
int D[1002][1002];
int A[1002][1002],d;
int main(){
PP S;
queue<PP> P;
int w,h;
int d=0,i=0,j=0,l=-1;
int x[4]={ 1, 0,-1,0};
int y[4]={ 0 ,1,0,-1};
scanf("%d %d %d",&h,&w,&d);
memset(A,0,sizeof(A));
memset(D,0,sizeof(D));
for(i=0;i<h;i++){
scanf("%s",s[i]);
}
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(s[i][j]=='S'){
S.x=j;
S.y=i;
S.Z=0;
S.c=1;
P.push(S);
}
}
}
while(1){
l++;
if(l==4) {
l=0;
P.pop();
}
S=P.front();
A[S.y][S.x]=1;
S.x+=x[l];
S.y+=y[l];
S.Z++;
if(A[S.y][S.x]==1||s[S.y][S.x]=='X'||S.y==h||S.x==w||S.x==-1||S.y==-1){
continue;
}
if(s[S.y][S.x]=='.'){}
else{
if(C[S.c]==s[S.y][S.x]){
S.c++;
if(S.c==d+1){
break;
}
while(!P.empty()){
P.pop();
}
memset(A,0,sizeof(A));
l=-1;
}
}
P.push(S);
}
printf("%d\n",S.Z);
return 0;
} | a.cc:1:9: fatal error: cstdio.h: No such file or directory
1 | #include<cstdio.h>
| ^~~~~~~~~~
compilation terminated.
|
s680723118 | p00481 | C++ | #include<iostream>
#include<cctype>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cassert>
#include<cctype>
#include<cstring>
#include<utility>
#include<cmath>
const int inf=0x7fffffff;
typedef long long int ll;
using namespace std;
const bool test=0;
int n,w,h;
int const N=1000+10;
char A[N][N];
char V[N][N];
char s[N];
int _h,_w;
int mov[2][4]={
0,0,-1,1,
-1,1,0,0
};
void show(){
if(test){
for(int i=1;i<=_h;i++){
for(int j=1;j<=_w;j++){
printf("%2d",A[i][j]);
}
printf("\n");
}
}
}
const int H=0,W=1;
struct point{
int h;
int w;
int cnt;
point(int h=1,int w=1,int cnt=inf):h(h),w(w),cnt(cnt){}
};
int cor(char x,int i,int j){
switch(x){
case 'S':
h=i;
w=j;
return 0;
break;
case 'X':
return -1;
case '.':
return 0;
default:
return x-'0';
}
}
int search(int goal){
memset(V,0,sizeof(V));
int cnt=0;
queue<point> q;
q.push(point(h,w,cnt));
point p;
if(test){cout<<"root"<<cnt<<' '<<h<<' '<<w<<endl;
show();
}
while(q.size()){
p=q.front();
q.pop();
h=p.h;
w=p.w;
cnt=p.cnt;
if(V[h][w]!=0)continue;
if(A[h][w]==goal){
return cnt;
}
if(test)cout<<"q.size "<<q.size()<<" cnt "<<cnt<<' '<<h<<' '<<w<<' '<<(int)V[h][w]<<" goal "<<goal<<endl;
for(int c=0;c<4;c++){
int tmph=h+mov[H][c];
int tmpw=w+mov[W][c];
if(!V[tmph][tmpw]&&A[h][w]!=-1)q.push(point(tmph,tmpw,cnt+1));
}
V[h][w]=1;
}
assert(q.size());
}
void solve(){
int sum=0;
for(int i=1;i<=n;i++){
sum+=search(i);
}
cout<<sum<<endl;
}
int main()
{
scanf("%d%d%d", &h,&w,&n);
_h=h;
_w=w;
memset(A,-1,sizeof(A));
for(int i=1;i<=_h;i++){
scanf("%s",s);
for(int j=1;j<=_w;j++){
A[i][j]=cor(s[j-1],i,j);
}
}
show();
solve();
return 0;
}
////aoj0558.cc
////generated automatically at Fri Sep 9 18:27:24 2016
////by xsthunder
/ | a.cc:118:1: error: expected unqualified-id before '/' token
118 | /
| ^
a.cc: In function 'int search(int)':
a.cc:91:1: warning: control reaches end of non-void function [-Wreturn-type]
91 | }
| ^
|
s723729208 | p00481 | C++ | #include <algorithm>
#include <cmath>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
/*------------------------------------------------------------------------------*/
int cost[1100][1100];
int main(){
int H, W, N;
cin >> H >> W >> N;
vector<string> s;
s.push_back(string(W+2, 'X'));
REP(i, 0, H){
string tmp;
cin >> tmp;
s.push_back('X' + tmp + 'X');
}
s.push_back(string(W+2, 'X'));
vector<PII> v(N+1);
REP(i, 0, H+2){
REP(j, 0, W+2){
char c = s[i][j];
if(c >= '1' && c <= '9'){
v[c-'0'] = {i, j};
} else if(c == 'S'){
v[0] = {i, j};
}
}
//cout << s[i] << endl;
}
int dest = 0, res = 0;
REP(i, 0, N){
queue<PII> q;
q.push(v[dest]);
memset(cost, -1, sizeof(cost));
cost[v[dest].fst][v[dest].snd] = 0;
while(!q.empty()){
PII a = q.front(); q.pop();
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
if(s[a.fst][a.snd] == i + '1'){
res += cost[a.fst][a.snd];
dest++;
break;
}
REP(i, 0, 4){
int ny = a.fst + dy[i];
int nx = a.snd + dx[i];
if(s[ny][nx] != 'X' && !(cost[ny][nx] + 1)){//cost[ny][nx] + 1 == 0 if not searched
cost[ny][nx] = cost[a.fst][a.snd] + 1;
q.push({ny, nx});
}
}
}
}
cout << res << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:69:5: error: 'memset' was not declared in this scope
69 | memset(cost, -1, sizeof(cost));
| ^~~~~~
a.cc:14:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
13 | #include <unordered_map>
+++ |+#include <cstring>
14 | #include <vector>
|
s188063155 | p00481 | C++ | #include <algorithm>
#include <cmath>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define fst first
#define snd second
#define MP make_pair //incase c++11 or later is not available
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;
/*------------------------------------------------------------------------------*/
int cost[1100][1100];
int main(){
int H, W, N;
cin >> H >> W >> N;
vector<string> s;
s.push_back(string(W+2, 'X'));
REP(i, 0, H){
string tmp;
cin >> tmp;
s.push_back('X' + tmp + 'X');
}
s.push_back(string(W+2, 'X'));
vector<PII> v(N+1);
REP(i, 0, H+2){
REP(j, 0, W+2){
char c = s[i][j];
if(c >= '1' && c <= '9'){
v[c-'0'] = {i, j};
} else if(c == 'S'){
v[0] = {i, j};
}
}
//cout << s[i] << endl;
}
int dest = 0, res = 0;
REP(i, 0, N){
queue<PII> q;
q.push(v[dest]);
memset(cost, -1, sizeof(cost));
cost[v[dest].fst][v[dest].snd] = 0;
while(!q.empty()){
PII a = q.front(); q.pop();
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
if(s[a.fst][a.snd] == i + '1'){
res += cost[a.fst][a.snd];
dest++;
break;
}
REP(i, 0, 4){
int ny = a.fst + dy[i];
int nx = a.snd + dx[i];
if(s[ny][nx] != 'X' && !(cost[ny][nx] + 1)){//cost[ny][nx] + 1 == 0 if not searched
cost[ny][nx] = cost[a.fst][a.snd] + 1;
q.push({ny, nx});
}
}
}
}
cout << res << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:69:5: error: 'memset' was not declared in this scope
69 | memset(cost, -1, sizeof(cost));
| ^~~~~~
a.cc:14:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
13 | #include <unordered_map>
+++ |+#include <cstring>
14 | #include <vector>
|
s351899591 | p00481 | C++ | 22:42
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# include <iostream>
# include <queue>
# include <cctype>
typedef std::pair<int, int> P;
テつ?
const int INF = 100000;
const int MAX_H = 1000;
const int MAX_W = 1000;
const int MAX_N = 9;
テつ?
int dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
int h, w, n;
int d[MAX_H][MAX_W];
char ch[MAX_H][MAX_W];
P p[MAX_N + 1];
テつ?
int bfs(P s, P g) {
テつ?つ?つ?つ?or (int i = 0; i<h; ++i) {
テつ?つ?つ?つ?つ?つ?つ?つ?or (int j = 0; j<w; ++j)
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?[i][j] = INF;
テつ?つ?つ?つ?
テつ?つ?つ?つ?td::queue<P> que;
テつ?つ?つ?つ?ue.push(s);
テつ?つ?つ?つ?[s.second][s.first] = 0;
テつ?つ?つ?つ?hile (!que.empty()) {
テつ?つ?つ?つ?つ?つ?つ?つ? x = que.front(); que.pop();
テつ?つ?つ?つ?つ?つ?つ?つ?f (x == g)
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?reak;
テつ?つ?つ?つ?つ?つ?つ?つ?or (int i = 0; i < 4; ++i) {
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?nt nx = x.first + dx[i];
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?nt ny = x.second + dy[i];
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?f (nx >= 0 && ny >= 0 && nx < w && ny < h && d[ny][nx] == INF && ch[ny][nx] != 'X') {
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?ue.push(P(nx, ny));
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?[ny][nx] = d[x.second][x.first] + 1;
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?
テつ?つ?つ?つ?つ?つ?つ?つ?
テつ?つ?つ?つ?
テつ?つ?つ?つ?eturn d[g.second][g.first];
}
テつ?
int solve() {
テつ?つ?つ?つ?nt res = 0;
テつ?つ?つ?つ?or (int i = 1; i <= n; ++i) {
テつ?つ?つ?つ?つ?つ?つ?つ?es += bfs(p[i - 1], p[i]);
テつ?つ?つ?つ?
テつ?つ?つ?つ?eturn res;
}
テつ?
int main() {
テつ?つ?つ?つ?td::cin >> h >> w >> n;
テつ?つ?つ?つ?or (int i = 0; i < h; ++i) {
テつ?つ?つ?つ?つ?つ?つ?つ?or (int j = 0; j < w; ++j) {
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?td::cin >> ch[i][j];
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?f (std::isdigit(ch[i][j])) {
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?[atoi(&ch[i][j])].first = j;
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?[atoi(&ch[i][j])].second = i;
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?lse if (ch[i][j] == 'S') {
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?[0].first = j;
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?[0].second = i;
テつ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?つ?
テつ?つ?つ?つ?つ?つ?つ?つ?
テつ?つ?つ?つ?
テつ?つ?つ?つ?td::cout << solve() << std::endl;
テつ?つ?つ?つ?eturn 0; | a.cc:1:1: error: expected unqualified-id before numeric constant
1 | 22:42
| ^~
In file included from /usr/include/c++/14/iosfwd:42,
from /usr/include/c++/14/ios:40,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:69:
/usr/include/c++/14/bits/postypes.h:68:11: error: 'ptrdiff_t' does not name a type
68 | typedef ptrdiff_t streamsize; // Signed integral type
| ^~~~~~~~~
/usr/include/c++/14/bits/postypes.h:41:1: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
40 | #include <cwchar> // For mbstate_t
+++ |+#include <cstddef>
41 |
In file included from /usr/include/c++/14/bits/exception_ptr.h:38,
from /usr/include/c++/14/exception:166,
from /usr/include/c++/14/ios:41:
/usr/include/c++/14/new:131:26: error: declaration of 'operator new' as non-function
131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~~~
/usr/include/c++/14/new:131:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~
In file included from /usr/include/wchar.h:35,
from /usr/include/c++/14/cwchar:44,
from /usr/include/c++/14/bits/postypes.h:40:
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:132:41: error: attributes after parenthesized initializer ignored [-fpermissive]
132 | __attribute__((__externally_visible__));
| ^
/usr/include/c++/14/new:133:26: error: declaration of 'operator new []' as non-function
133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~~~
/usr/include/c++/14/new:133:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:134:41: error: attributes after parenthesized initializer ignored [-fpermissive]
134 | __attribute__((__externally_visible__));
| ^
/usr/include/c++/14/new:140:29: error: 'std::size_t' has not been declared
140 | void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
| ^~~
/usr/include/c++/14/new:142:31: error: 'std::size_t' has not been declared
142 | void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT
| ^~~
/usr/include/c++/14/new:145:26: error: declaration of 'operator new' as non-function
145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/14/new:145:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:145:52: error: expected primary-expression before 'const'
145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~
/usr/include/c++/14/new:147:26: error: declaration of 'operator new []' as non-function
147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/14/new:147:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:147:54: error: expected primary-expression before 'const'
147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
| ^~~~~
/usr/include/c++/14/new:154:26: error: declaration of 'operator new' as non-function
154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
| ^~~~~~~~
/usr/include/c++/14/new:154:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:154:68: error: expected primary-expression before ')' token
154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t)
| ^
/usr/include/c++/14/new:155:73: error: attributes after parenthesized initializer ignored [-fpermissive]
155 | __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
| ^
/usr/include/c++/14/new:156:26: error: declaration of 'operator new' as non-function
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~~~
/usr/include/c++/14/new:156:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:156:68: error: expected primary-expression before ',' token
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^
/usr/include/c++/14/new:156:70: error: expected primary-expression before 'const'
156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~
/usr/include/c++/14/new:162:26: error: declaration of 'operator new []' as non-function
162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
| ^~~~~~~~
/usr/include/c++/14/new:162:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:162:70: error: expected primary-expression before ')' token
162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t)
| ^
/usr/include/c++/14/new:163:73: error: attributes after parenthesized initializer ignored [-fpermissive]
163 | __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__));
| ^
/usr/include/c++/14/new:164:26: error: declaration of 'operator new []' as non-function
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~~~
/usr/include/c++/14/new:164:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/new:164:70: error: expected primary-expression before ',' token
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^
/usr/include/c++/14/new:164:72: error: expected primary-expression before 'const'
164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&)
| ^~~~~
/usr/include/c++/14/new:171:29: error: 'std::size_t' has not been declared
171 | void operator delete(void*, std::size_t, std::align_val_t)
| ^~~
/usr/include/c++/14/new:173:31: error: 'std::size_t' has not been declared
173 | void operator delete[](void*, std::size_t, std::align_val_t)
| ^~~
/usr/include/c++/14/new:179:33: error: declaration of 'operator new' as non-function
179 | _GLIBCXX_NODISCARD inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/14/new:179:51: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
179 | _GLIBCXX |
s444125414 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
const int INF = 1<<30;
const int maxn = 1000+10;
int w,h,n;
char mp[maxn][maxn];
int d[maxn][maxn];
int dir[4][2] = {
{-1,0},
{1,0},
{0,1},
{0,-1},
};
int fac[10][2];
int bfs(int sx,int sy,int gx,int gy){
memset(d,-1,sizeof(d));
queue<pair<int,int> > Q;
Q.push(make_pair(sx,sy));
d[sx][sy] = 0;
while(!Q.empty()){
pair<int,int> p = Q.front(); Q.pop();
if(p.first==gx && p.second==gy) break;
for(int i=0; i<4; i++){
int tx = p.first + dir[i][0];
int ty = p.second + dir[i][1];
if(tx>=0 && tx<h && ty>=0 && ty<w && mp[tx][ty]!='X' && d[tx][ty]==-1){
Q.push(make_pair(tx,ty));
d[tx][ty] = d[p.first][p.second] + 1;
}
}
}
return d[gx][gy];
}
int main(){
scanf("%d%d%d",&h,&w,&n);
for(int i=0; i<h; i++)
for(int j=0; j<w; j++)
cin >> mp[i][j];
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
if(mp[i][j] == 'S'){
fac[0][0] = i;
fac[0][1] = j;
mp[i][j] = '.';
}else if(isdigit(mp[i][j])){
int index = mp[i][j] - '0';
fac[index][0] = i;
fac[index][1] = j;
}
}
}
int step = 0;
for(int i=0; i<n; i++){
step += bfs(fac[i][0],fac[i][1],fac[i+1][0],fac[i+1][1]);
}
printf("%d\n",step);
} | a.cc: In function 'int bfs(int, int, int, int)':
a.cc:24:9: error: 'memset' was not declared in this scope
24 | memset(d,-1,sizeof(d));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <queue>
+++ |+#include <cstring>
5 | using namespace std;
|
s274747503 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
const int INF = 1<<30;
const int maxn = 1000+10;
int w,h,n;
char mp[maxn][maxn];
int d[maxn][maxn];
int dir[4][2] = {
{-1,0},
{1,0},
{0,1},
{0,-1},
};
int fac[10][2];
int bfs(int sx,int sy,int gx,int gy){
memset(d,-1,sizeof(d));
queue<pair<int,int> > Q;
Q.push(make_pair(sx,sy));
d[sx][sy] = 0;
while(!Q.empty()){
pair<int,int> p = Q.front(); Q.pop();
if(p.first==gx && p.second==gy) break;
for(int i=0; i<4; i++){
int tx = p.first + dir[i][0];
int ty = p.second + dir[i][1];
if(tx>=0 && tx<h && ty>=0 && ty<w && mp[tx][ty]!='X' && d[tx][ty]==-1){
Q.push(make_pair(tx,ty));
d[tx][ty] = d[p.first][p.second] + 1;
}
}
}
return d[gx][gy];
}
int main(){
scanf("%d%d%d",&h,&w,&n);
for(int i=0; i<h; i++)
for(int j=0; j<w; j++)
cin >> mp[i][j];
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
if(mp[i][j] == 'S'){
fac[0][0] = i;
fac[0][1] = j;
mp[i][j] = '.';
}else if(isdigit(mp[i][j])){
int index = mp[i][j] - '0';
fac[index][0] = i;
fac[index][1] = j;
}
}
}
int step = 0;
for(int i=0; i<n; i++){
step += bfs(fac[i][0],fac[i][1],fac[i+1][0],fac[i+1][1]);
}
printf("%d\n",step);
} | a.cc: In function 'int bfs(int, int, int, int)':
a.cc:24:9: error: 'memset' was not declared in this scope
24 | memset(d,-1,sizeof(d));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <queue>
+++ |+#include <cstring>
5 | using namespace std;
|
s150355146 | p00481 | C++ | #pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
using namespace std;
string S[1001];
long result=0;
int H,W,N;
long mintime[1000][1000];
queue<int> qx,qy,time;
int sx,sy,gx,gy;
int step = 0;
FILE *fp;
int main(){
fp = fopen("answer.txt","w");
scanf("%d%d%d",&H,&W,&N);
for(int i=0;i<H;i++){
cin>>S[i];
for(int j=0;j<W;j++){
mintime[i][j]=1000000;
if(S[i][j]=='S'){
sx=j;
sy=i;
qx.push(j);
qy.push(i);
time.push(0);
}
if(S[i][j]-'0'==N){
gx=j;
gy=i;
}
}
}
for(int acc=0;acc<N;acc++){
step++;
while(step<=N){
if(qx.front()>0){
if(time.front()<mintime[qy.front()][qx.front()-1]-1 && S[qy.front()][qx.front()-1] !='X'){
if(S[qy.front()][qx.front()-1]-'0' ==step){
result += time.front()+1;
sx=qx.front()-1;
sy=qy.front();
while(qx.empty()== false){
qx.pop();
qy.pop();
time.pop();
}
qx.push(sx);
qy.push(sy);
time.push(0);
break;
}
qx.push(qx.front()-1);
qy.push(qy.front());
time.push(time.front()+1);
mintime[qy.front()][qx.front()-1]=time.front()+1;
}
}
//
if( qx.front()<W-1 ){
if(time.front()<mintime[qy.front()][qx.front()+1]-1 && S[qy.front()][qx.front()+1] !='X'){
if(S[qy.front()][qx.front()+1]-'0' ==step){
result += time.front()+1;
sx=qx.front()+1;
sy=qy.front();
while(qx.empty()== false){
qx.pop();
qy.pop();
time.pop();
}
qx.push(sx);
qy.push(sy);
time.push(0);
break;
}
qx.push(qx.front()+1);
qy.push(qy.front());
time.push(time.front()+1);
mintime[qy.front()][qx.front()+1]=time.front()+1;
}
}
//
if( qy.front()>0){
if(time.front()<mintime[qy.front()-1][qx.front()]-1 && S[qy.front()-1][qx.front()] !='X'){
if(S[qy.front()-1][qx.front()]-'0' ==step){
result += time.front()+1;
sx=qx.front();
sy=qy.front()-1;
while(qx.empty()== false){
qx.pop();
qy.pop();
time.pop();
}
qx.push(sx);
qy.push(sy);
time.push(0);
break;
}
qx.push(qx.front());
qy.push(qy.front()-1);
time.push(time.front()+1);
mintime[qy.front()-1][qx.front()]=time.front()+1;
}
}
//
if(qy.front()<H-1){
if(time.front()<mintime[qy.front()+1][qx.front()]-1 && S[qy.front()+1][qx.front()] !='X'){
if(S[qy.front()+1][qx.front()]-'0' ==step){
result += time.front()+1;
sx=qx.front();
sy=qy.front()+1;
while(qx.empty()== false){
qx.pop();
qy.pop();
time.pop();
}
qx.push(sx);
qy.push(sy);
time.push(0);
break;
}
qx.push(qx.front());
qy.push(qy.front()+1);
time.push(time.front()+1);
mintime[qy.front()+1][qx.front()]=time.front()+1;
}
}
qx.pop();
qy.pop();
time.pop();
}
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
mintime[i][j]=1000000;
}
}
}
printf("%d\n",result);
fprintf(fp,"%d\n",result);
fclose(fp);
return 0;
} | a.cc:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
a.cc:12:18: error: 'std::queue<int> time' redeclared as different kind of entity
12 | queue<int> qx,qy,time;
| ^~~~
In file included from /usr/include/pthread.h:23,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
from /usr/include/c++/14/ext/atomicity.h:35,
from /usr/include/c++/14/bits/ios_base.h:39,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:5:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
76 | extern time_t time (time_t *__timer) __THROW;
| ^~~~
a.cc: In function 'int main()':
a.cc:30:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
30 | time.push(0);
| ^~~~
a.cc:48:25: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
48 | if(time.front()<mintime[qy.front()][qx.front()-1]-1 && S[qy.front()][qx.front()-1] !='X'){
| ^~~~~
a.cc:50:40: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
50 | result += time.front()+1;
| ^~~~~
a.cc:56:38: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
56 | time.pop();
| ^~~
a.cc:61:30: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
61 | time.push(0);
| ^~~~
a.cc:66:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
66 | time.push(time.front()+1);
| ^~~~
a.cc:66:48: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
66 | time.push(time.front()+1);
| ^~~~~
a.cc:67:72: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
67 | mintime[qy.front()][qx.front()-1]=time.front()+1;
| ^~~~~
a.cc:74:25: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
74 | if(time.front()<mintime[qy.front()][qx.front()+1]-1 && S[qy.front()][qx.front()+1] !='X'){
| ^~~~~
a.cc:77:40: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
77 | result += time.front()+1;
| ^~~~~
a.cc:83:38: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
83 | time.pop();
| ^~~
a.cc:88:30: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
88 | time.push(0);
| ^~~~
a.cc:94:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
94 | time.push(time.front()+1);
| ^~~~
a.cc:94:48: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
94 | time.push(time.front()+1);
| ^~~~~
a.cc:95:72: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
95 | mintime[qy.front()][qx.front()+1]=time.front()+1;
| ^~~~~
a.cc:102:25: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
102 | if(time.front()<mintime[qy.front()-1][qx.front()]-1 && S[qy.front()-1][qx.front()] !='X'){
| ^~~~~
a.cc:105:40: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
105 | result += time.front()+1;
| ^~~~~
a.cc:111:38: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
111 | time.pop();
| ^~~
a.cc:116:30: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
116 | time.push(0);
| ^~~~
a.cc:122:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
122 | time.push(time.front()+1);
| ^~~~
a.cc:122:48: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
122 | time.push(time.front()+1);
| ^~~~~
a.cc:123:72: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
123 | mintime[qy.front()-1][qx.front()]=time.front()+1;
| ^~~~~
a.cc:130:25: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
130 | if(time.front()<mintime[qy.front()+1][qx.front()]-1 && S[qy.front()+1][qx.front()] !='X'){
| ^~~~~
a.cc:133:40: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
133 | result += time.front()+1;
| ^~~~~
a.cc:139:38: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
139 | time.pop();
| ^~~
a.cc:144:30: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
144 | time.push(0);
| ^~~~
a.cc:150:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
150 | time.push(time.front()+1);
| ^~~~
a.cc:150:48: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
150 | time.push(time.front()+1);
| ^~~~~
a.cc:151:72: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
151 | mintime[qy.front()+1][qx.front()]=time.front()+1;
| ^~~~~
a.cc:158:22: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
158 | time.pop();
| ^~~
|
s395851990 | p00481 | C++ | #pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
using namespace std;
string S[1001];
long result=0;
int H,W,N;
long mintime[1000][1000];
queue<int> qx,qy,time;
int sx,sy,gx,gy;
int step = 0;
int main(){
scanf("%d%d%d",&H,&W,&N);
for(int i=0;i<H;i++){
cin>>S[i];
for(int j=0;j<W;j++){
mintime[i][j]=1000000;
if(S[i][j]=='S'){
sx=j;
sy=i;
qx.push(j);
qy.push(i);
time.push(0);
}
if(S[i][j]-'0'==N){
gx=j;
gy=i;
}
}
}
for(int acc=0;acc<N;acc++){
step++;
while(step<=N){
if(qx.front()>0){
if(time.front()<mintime[qy.front()][qx.front()-1]-1 && S[qy.front()][qx.front()-1] !='X'){
if(S[qy.front()][qx.front()-1]-'0' ==step){
result += time.front()+1;
sx=qx.front()-1;
sy=qy.front();
while(qx.empty()== false){
qx.pop();
qy.pop();
time.pop();
}
qx.push(sx);
qy.push(sy);
time.push(0);
break;
}
qx.push(qx.front()-1);
qy.push(qy.front());
time.push(time.front()+1);
mintime[qy.front()][qx.front()-1]=time.front()+1;
}
}
//
if( qx.front()<W-1 ){
if(time.front()<mintime[qy.front()][qx.front()+1]-1 && S[qy.front()][qx.front()+1] !='X'){
if(S[qy.front()][qx.front()+1]-'0' ==step){
result += time.front()+1;
sx=qx.front()+1;
sy=qy.front();
while(qx.empty()== false){
qx.pop();
qy.pop();
time.pop();
}
qx.push(sx);
qy.push(sy);
time.push(0);
break;
}
qx.push(qx.front()+1);
qy.push(qy.front());
time.push(time.front()+1);
mintime[qy.front()][qx.front()+1]=time.front()+1;
}
}
//
if( qy.front()>0){
if(time.front()<mintime[qy.front()-1][qx.front()]-1 && S[qy.front()-1][qx.front()] !='X'){
if(S[qy.front()-1][qx.front()]-'0' ==step){
result += time.front()+1;
sx=qx.front();
sy=qy.front()-1;
while(qx.empty()== false){
qx.pop();
qy.pop();
time.pop();
}
qx.push(sx);
qy.push(sy);
time.push(0);
break;
}
qx.push(qx.front());
qy.push(qy.front()-1);
time.push(time.front()+1);
mintime[qy.front()-1][qx.front()]=time.front()+1;
}
}
//
if(qy.front()<H-1){
if(time.front()<mintime[qy.front()+1][qx.front()]-1 && S[qy.front()+1][qx.front()] !='X'){
if(S[qy.front()+1][qx.front()]-'0' ==step){
result += time.front()+1;
sx=qx.front();
sy=qy.front()+1;
while(qx.empty()== false){
qx.pop();
qy.pop();
time.pop();
}
qx.push(sx);
qy.push(sy);
time.push(0);
break;
}
qx.push(qx.front());
qy.push(qy.front()+1);
time.push(time.front()+1);
mintime[qy.front()+1][qx.front()]=time.front()+1;
}
}
qx.pop();
qy.pop();
time.pop();
}
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
mintime[i][j]=1000000;
}
}
}
printf("%d\n",result);
return 0;
} | a.cc:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
a.cc:12:18: error: 'std::queue<int> time' redeclared as different kind of entity
12 | queue<int> qx,qy,time;
| ^~~~
In file included from /usr/include/pthread.h:23,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
from /usr/include/c++/14/ext/atomicity.h:35,
from /usr/include/c++/14/bits/ios_base.h:39,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:5:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
76 | extern time_t time (time_t *__timer) __THROW;
| ^~~~
a.cc: In function 'int main()':
a.cc:28:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
28 | time.push(0);
| ^~~~
a.cc:46:25: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
46 | if(time.front()<mintime[qy.front()][qx.front()-1]-1 && S[qy.front()][qx.front()-1] !='X'){
| ^~~~~
a.cc:48:40: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
48 | result += time.front()+1;
| ^~~~~
a.cc:54:38: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
54 | time.pop();
| ^~~
a.cc:59:30: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
59 | time.push(0);
| ^~~~
a.cc:64:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
64 | time.push(time.front()+1);
| ^~~~
a.cc:64:48: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
64 | time.push(time.front()+1);
| ^~~~~
a.cc:65:72: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
65 | mintime[qy.front()][qx.front()-1]=time.front()+1;
| ^~~~~
a.cc:72:25: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
72 | if(time.front()<mintime[qy.front()][qx.front()+1]-1 && S[qy.front()][qx.front()+1] !='X'){
| ^~~~~
a.cc:75:40: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
75 | result += time.front()+1;
| ^~~~~
a.cc:81:38: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
81 | time.pop();
| ^~~
a.cc:86:30: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
86 | time.push(0);
| ^~~~
a.cc:92:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
92 | time.push(time.front()+1);
| ^~~~
a.cc:92:48: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
92 | time.push(time.front()+1);
| ^~~~~
a.cc:93:72: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
93 | mintime[qy.front()][qx.front()+1]=time.front()+1;
| ^~~~~
a.cc:100:25: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
100 | if(time.front()<mintime[qy.front()-1][qx.front()]-1 && S[qy.front()-1][qx.front()] !='X'){
| ^~~~~
a.cc:103:40: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
103 | result += time.front()+1;
| ^~~~~
a.cc:109:38: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
109 | time.pop();
| ^~~
a.cc:114:30: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
114 | time.push(0);
| ^~~~
a.cc:120:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
120 | time.push(time.front()+1);
| ^~~~
a.cc:120:48: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
120 | time.push(time.front()+1);
| ^~~~~
a.cc:121:72: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
121 | mintime[qy.front()-1][qx.front()]=time.front()+1;
| ^~~~~
a.cc:128:25: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
128 | if(time.front()<mintime[qy.front()+1][qx.front()]-1 && S[qy.front()+1][qx.front()] !='X'){
| ^~~~~
a.cc:131:40: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
131 | result += time.front()+1;
| ^~~~~
a.cc:137:38: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
137 | time.pop();
| ^~~
a.cc:142:30: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
142 | time.push(0);
| ^~~~
a.cc:148:38: error: request for member 'push' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
148 | time.push(time.front()+1);
| ^~~~
a.cc:148:48: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
148 | time.push(time.front()+1);
| ^~~~~
a.cc:149:72: error: request for member 'front' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
149 | mintime[qy.front()+1][qx.front()]=time.front()+1;
| ^~~~~
a.cc:156:22: error: request for member 'pop' in 'time', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
156 | time.pop();
| ^~~
|
s544604699 | p00481 | C++ | #include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int h,w,n;
char m[1000][1000];
int visited[1000][1000];
int main(){
cin>>h>>w>>n;
int pos;
for(int y=0;y<h;y++){
for(int x=0;x<w;x++){
cin>>m[x][y];
if(m[x][y]=='S') pos=x+y*1000;
}
}
memset(visited,0,sizeof(visited));
int ans=0;
for(int now=1;now<=n;now++){
queue<P> q;
q.push(make_pair(pos,0));
while(1){
pos=q.front().first;
int x=pos%1000;
int y=pos/1000;
int cost=q.front().second;
q.pop();
if(visited[x][y]==now || m[x][y]=='X') continue;
if(m[x][y]==('0'+now)){
ans+=cost;
break;
}
visited[x][y]=now;
if(0<x) q.push(make_pair(pos-1,cost+1));
if(x+1<w) q.push(make_pair(pos+1,cost+1));
if(0<y) q.push(make_pair(pos-1000,cost+1));
if(y+1<h) q.push(make_pair(pos+1000,cost+1));
}
}
cout<<ans<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:23:9: error: 'memset' was not declared in this scope
23 | memset(visited,0,sizeof(visited));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include<algorithm>
+++ |+#include <cstring>
4 | using namespace std;
|
s611874898 | p00481 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>
using namespace std;
typedef pair<int, int> P;
int h, w, n;
char f[1000][1000];
int dx[] = { 0, 1, 0, -1 };
int dy[] = { -1, 0, 1, 0 };
struct Ele {
Ele(int a, double b, P c) : g(a), h(b), p(c) {}
bool operator<(const Ele& right) const {
return g + h > right.g + right.h;
}
int g;
double h;
P p;
};
double euclidean(P s, P g) {
int y = s.first - g.first;
int x = s.second - g.second;
return sqrt(x*x + y*y);
}
int Astar(P s, P g) {
bool used[1000][1000] = { false };
priority_queue<Ele> que;
que.push(Ele(0, euclidean(s, g), s));
while (!que.empty()) {
Ele t = que.top();
que.pop();
if (t.p == g)
return t.g;
if (used[t.p.first][t.p.second])
continue;
used[t.p.first][t.p.second] = true;
for (int i = 0; i < 4; ++i) {
int ny = t.p.first + dy[i];
int nx = t.p.second + dx[i];
if (ny < 0 || ny >= h || nx < 0 || nx >= w || f[ny][nx] == 'X')
continue;
P np(ny, nx);
que.push(Ele(t.g + 1, euclidean(np, g), np));
}
}
return 0;
}
int main() {
cin >> h >> w >> n;
P fac[10];
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> f[i][j];
if ('1' <= f[i][j] && f[i][j] <= '9')
fac[f[i][j] - '0'] = P(i, j);
else if (f[i][j] == 'S')
fac[0] = P(i, j);
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
ans += Astar(fac[i], fac[i + 1]);
}
cout << ans << endl;
return 0;
} | a.cc: In function 'double euclidean(P, P)':
a.cc:33:16: error: 'sqrt' was not declared in this scope
33 | return sqrt(x*x + y*y);
| ^~~~
|
s651941194 | p00481 | C++ | #include <iostream>
#include <stdlib.h>
#include <queue>
#define MAX_NUM 1010
using namespace std;
int H, W, N;
bool flag[MAX_NUM][MAX_NUM] = {false};
class Node
{
public:
Node();
Node(int x, int y, int step);
~Node();
int x;
int y;
int step;
};
Node::Node()
{
}
Node::Node(int x, int y, int step) {
this->x = x;
this->y = y;
this->step = step;
}
Node::~Node()
{
}
int dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
int BFS(char map[][MAX_NUM], int sx, int sy, int ex, int ey) {
queue<Node*> que;
que.push(new Node(sx, sy, 0));
flag[sx][sy] = true;
while (!que.empty())
{
Node* cur = que.front();
que.pop();
if (cur->x == ex && cur->y == ey)
{
return cur->step;
}
else
{
for (int i = 0; i < 4; i++)
{
int k = cur->x + dir[i][0];
int v = cur->y + dir[i][1];
if (k>=0&&k<H&&v>=0&&v<W&&map[k][v]!='X'&&!flag[k][v])
{
que.push(new Node(k, v, cur->step + 1));
flag[k][v] = true;
}
}
}
}
return -1;
}
int main()
{
int sx, sy, arr[10][2];
char map[MAX_NUM][MAX_NUM];
while (cin >> H >> W >> N && H && W)
{
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
cin >> map[i][j];
if (map[i][j] == 'S')
{
map[i][j] = '.';
sx = i;
sy = j;
}
if (isdigit(map[i][j]))
{
int index = map[i][j] - '0';
arr[index][0] = i;
arr[index][1] = j;
}
}
}
memset(flag, false, sizeof(flag));
int res = 0;
res += BFS(map, sx, sy, arr[1][0], arr[1][1]);
for (int i = 1; i+1 <= N; i++)
{
memset(flag, false, sizeof(flag));
res += BFS(map, arr[i][0], arr[i][1], arr[i + 1][0], arr[i + 1][1]);
}
cout << res << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:89:17: error: 'memset' was not declared in this scope
89 | memset(flag, false, sizeof(flag));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 | #define MAX_NUM 1010
|
s561200092 | p00481 | C++ | #include <iostream>
#include <stdlib.h>
#include <queue>
#define MAX_NUM 1010
using namespace std;
int H, W, N;
bool flag[MAX_NUM][MAX_NUM] = {false};
class Node
{
public:
Node();
Node(int x, int y, int step);
~Node();
int x;
int y;
int step;
};
Node::Node()
{
}
Node::Node(int x, int y, int step) {
this->x = x;
this->y = y;
this->step = step;
}
Node::~Node()
{
}
int dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
int BFS(char map[][MAX_NUM], int sx, int sy, int ex, int ey) {
queue<Node> que;
Node node(sx, sy, 0);
que.push(node);
flag[sx][sy] = true;
while (!que.empty())
{
Node cur = que.front();
que.pop();
if (cur.x == ex && cur.y == ey)
{
return cur.step;
}
else
{
for (int i = 0; i < 4; i++)
{
int k = cur.x + dir[i][0];
int v = cur.y + dir[i][1];
if (k>=0&&k<H&&v>=0&&v<W&&map[k][v]!='X'&&!flag[k][v])
{
Node temp(k, v, cur.step + 1);
que.push(temp);
flag[k][v] = true;
}
}
}
}
return -1;
}
int main()
{
int sx, sy, arr[10][2];
char map[MAX_NUM][MAX_NUM];
while (cin >> H >> W >> N && H && W)
{
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
cin >> map[i][j];
if (map[i][j] == 'S')
{
map[i][j] = '.';
sx = i;
sy = j;
}
if (isdigit(map[i][j]))
{
int index = map[i][j] - '0';
arr[index][0] = i;
arr[index][1] = j;
}
}
}
arr[0][0] = sx;
arr[0][1] = sy;
int res = 0;
for (int i = 0; i+1 <= N; i++)
{
memset(flag, false, sizeof(flag));
res += BFS(map, arr[i][0], arr[i][1], arr[i + 1][0], arr[i + 1][1]);
}
cout << res << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:96:25: error: 'memset' was not declared in this scope
96 | memset(flag, false, sizeof(flag));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 | #define MAX_NUM 1010
|
s113261638 | p00481 | C++ | /*
* AOJ 0558: Cheese
* ?¢???????m*n???????????????????????????1???N??¨???N?????\??????????¢??????????????±????????????????1???N???????????????
* ?±???????BFS???Queue??????Dijkstra???
* ????????????S????????????1???N????????????????????\??¨BFS?±?N?¬???????????????´??????????????????
*/
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> pii;
int m, n, N;
char mat[1002][1002];
int d[1002][1002];
int sx[10], sy[10];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int ans;
int bfs(int sx, int sy, int tx, int ty) {
memset(d, -1, sizeof(d));
d[sx][sy] = 0;
queue<pii> q;
q.push(make_pair(sx, sy));
int x, y, xx, yy;
while (!q.empty()) {
pii cur = q.front();
q.pop();
x = cur.first;
y = cur.second;
for (int i = 0; i < 4; ++i) {
xx = x + dx[i];
yy = y + dy[i];
if (xx >= 0 && xx < m && yy >= 0 && yy < n && mat[xx][yy] != 'X' && d[xx][yy] == -1) {
d[xx][yy] = d[x][y] + 1;
if (xx == tx && yy == ty) {
return d[xx][yy];
}
q.push(make_pair(xx, yy));
}
}
}
}
void solve() {
ans = 0;
for (int i = 0; i < m; ++i) {
cin >> mat[i];
for (int j = 0; j < n; ++j) {
if (mat[i][j] == 'S') {
sx[0] = i;
sy[0] = j;
} else if (mat[i][j] >= '1' && mat[i][j] <= '9') {
int t = mat[i][j] - '0';
sx[t] = i;
sy[t] = j;
}
}
}
for (int i = 1; i <= N; ++i) {
int tmp = bfs(sx[i - 1], sy[i - 1], sx[i], sy[i]);
ans += tmp;
}
}
int main() {
cin >> m >> n >> N;
solve();
cout << ans << endl;
return 0;
} | a.cc: In function 'int bfs(int, int, int, int)':
a.cc:25:3: error: 'memset' was not declared in this scope
25 | memset(d, -1, sizeof(d));
| ^~~~~~
a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
10 | #include <queue>
+++ |+#include <cstring>
11 |
a.cc:48:1: warning: control reaches end of non-void function [-Wreturn-type]
48 | }
| ^
|
s471593898 | p00481 | C++ | #include <cstdio>
#include <vector>
const int MAX_SIZE = 1000;
char field[MAX_SIZE + 1][MAX_SIZE + 1];
const int STEP_NUM = 4;
const int STEP[STEP_NUM][STEP_NUM] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
using Position = std::pair<int,int>;
const int MAXN = 10;
Position locations[MAXN];
int H, W, N;
int get_shortest_distance(int current_HP)
{
int sx = locations[current_HP-1].first;
int sy = locations[current_HP-1].second;
int ex = locations[current_HP].first;
int ey = locations[current_HP].second;
bool is_visit[MAX_SIZE + 1][MAX_SIZE + 1]={};
is_visit[sx][sy]=true;
std::vector<Position> frontier(1,Position{sx,sy});
for(int step=0;step<W*H;step++)
{
std::vector<Position> next_frontier;
for(auto p:frontier)
for(int i=0;i<STEP_NUM;i++)
{
int nx = p.first+STEP[i][0];
int ny = p.second+STEP[i][1];
if(nx==ex && ny==ey) return step+1;
if(nx<0 || H<=nx) continue;
if(ny<0 || W<=ny) continue;
if(field[nx][ny]=='X') continue;
if(is_visit[nx][ny]) continue;
next_frontier.push_back(std::make_pair(nx,ny));
is_visit[nx][ny] = true;
}
frontier = next_frontier;
}
return -1;
}
int solve()
{
int total_step = 0;
for(int i=1;i<N+1;i++)
total_step += get_shortest_distance(i);
return total_step;
}
int main()
{
scanf("%d %d %d", &H, &W, &N);
for(int i=0; i<H; i++)
scanf("%s", field[i]);
for(int i=0; i<H; i++)
for(int j=0; j<W; j++)
{
if(field[i][j]=='S')
locations[0] = std::make_pair(i,j);
if(isdigit(field[i][j]))
locations[field[i][j]-'0'] = std::make_pair(i,j);
}
printf("%d\n", solve());
return 0;
} | a.cc: In function 'int main()':
a.cc:67:28: error: 'isdigit' was not declared in this scope
67 | if(isdigit(field[i][j]))
| ^~~~~~~
|
s705551805 | p00481 | C++ | #include <cstdio>
#include <vector>
const int MAX_SIZE = 1000;
char field[MAX_SIZE + 1][MAX_SIZE + 1];
const int STEP_NUM = 4;
const int STEP[STEP_NUM][STEP_NUM] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
using Position = std::pair<int,int>;
const int MAXN = 10;
Position locations[MAXN];
int H, W, N;
int get_shortest_distance(int current_HP)
{
int sx = locations[current_HP-1].first;
int sy = locations[current_HP-1].second;
int ex = locations[current_HP].first;
int ey = locations[current_HP].second;
bool is_visit[MAX_SIZE + 1][MAX_SIZE + 1]={};
is_visit[sx][sy]=true;
std::vector<Position> frontier;
frontier.push_back(Position{sx,sy});
for(int step=0;step<W*H;step++)
{
std::vector<Position> next_frontier;
for(auto p:frontier)
for(int i=0;i<STEP_NUM;i++)
{
int nx = p.first+STEP[i][0];
int ny = p.second+STEP[i][1];
if(nx==ex && ny==ey) return step+1;
if(nx<0 || H<=nx) continue;
if(ny<0 || W<=ny) continue;
if(field[nx][ny]=='X') continue;
if(is_visit[nx][ny]) continue;
next_frontier.push_back(std::make_pair(nx,ny));
is_visit[nx][ny] = true;
}
frontier = next_frontier;
}
return -1;
}
int solve()
{
int total_step = 0;
for(int i=1;i<N+1;i++)
total_step += get_shortest_distance(i);
return total_step;
}
int main()
{
scanf("%d %d %d", &H, &W, &N);
for(int i=0; i<H; i++)
scanf("%s", field[i]);
for(int i=0; i<H; i++)
for(int j=0; j<W; j++)
{
if(field[i][j]=='S')
locations[0] = std::make_pair(i,j);
if(isdigit(field[i][j]))
locations[field[i][j]-'0'] = std::make_pair(i,j);
}
printf("%d\n", solve());
return 0;
} | a.cc: In function 'int main()':
a.cc:68:28: error: 'isdigit' was not declared in this scope
68 | if(isdigit(field[i][j]))
| ^~~~~~~
|
s615816977 | p00481 | C++ | #include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#define p(x) cout << "(" << x.first << "," << x.second << ")" << endl;
using namespace std;
const int MAX_H = 1005;
const int MAX_W = 1005;
char D[MAX_H][MAX_W];
bool visited[MAX_H][MAX_W];
int H, W, N;
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, -1, 0, 1 };
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef vector<PII> VII;
int bfs(PII from, PII to) {
queue<PIII> que;
memset(visited, false, sizeof(visited[0][0]) * MAX_H * MAX_W);
que.push(make_pair(from, 0));
while (!que.empty()) {
PIII p = que.front(); que.pop();
int d = p.second;
if (p.first == to) {
return d;
}
for (int k = 0; k < 4; k++) {
int i2 = p.first.first + dx[k];
int j2 = p.first.second + dy[k];
if (0 <= i2 && i2 < H && 0 <= j2 && j2 < W && D[i2][j2] != 'X' && !visited[i2][j2]) {
visited[i2][j2] = true;
que.push(make_pair(make_pair(i2, j2), d+1));
}
}
}
return -1;
}
int main() {
cin >> H >> W >> N;
VII pos(N+1);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char c;
cin >> c;
D[i][j] = c;
if (c == 'S') {
pos[0] = make_pair(i, j);
} else if (c > '0') {
pos[c - '0'] = make_pair(i, j);
}
}
}
int res = 0;
for (int i = 0; i < N; i++) {
res += bfs(pos[i], pos[i+1]);
}
cout << res << endl;
return 0;
} | a.cc: In function 'int bfs(PII, PII)':
a.cc:26:3: error: 'memset' was not declared in this scope
26 | memset(visited, false, sizeof(visited[0][0]) * MAX_H * MAX_W);
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 | #include <vector>
|
s601556899 | p00481 | C++ | import sys
sys.setrecursionlimit(100000000)
def getStart(field):
search_field = field[1:] # cut the first [H,W,N] for min_path matrix
for y in range(len(search_field)):
for x in range(len(search_field[0])):
if search_field[y][x] == "S":
return x,y+1
def bfs(field,start_x,start_y,goal_N):
direction = [[-1,0],[1,0],[0,-1],[0,1]]
gotten_cheese = 1
distance = 0
que = []
que.append([start_x,start_y,gotten_cheese,distance])
INF = 1
min_path = [[INF for j in range(field[0][1])] for i in range(field[0][0])]
while len(que) != 0:
current = que.pop(0)
print("pop",current)
for d in direction:
nx = current[0] + d[0]
ny = current[1] + d[1]
if 0 <= nx < field[0][1] and 1 <= ny < field[0][0]+1 and field[ny][nx] != "X" and min_path[ny-1][nx] == INF:
if field[ny][nx] == current[2]: # at the same cheese-power number
if field[ny][nx] == goal_N: # goal
print(current[3]+1)
return
else: # not goal, but could eat cheese
que = []
que.append([nx,ny,current[2]+1,current[3]+1])
min_path = [[INF for j in range(field[0][1])] for i in range(field[0][0])]
break
else:
que.append([nx,ny,current[2],current[3]+1])
min_path[ny-1][nx] = 0
def main(field):
# field = [[10,10,9],
# [".","X",".",".",".","X",".","S",".","X"],
# [6,".",".",5,"X",".",".","X",1,"X"],
# [".",".",".","X","X","X","X",".",".","X"],
# ["X",".",".",9,"X",".",".",".","X","."],
# [8,".","X",2,"X",".",".","X",3,"X"],
# [".",".",".","X","X",".","X",4,".","."],
# ["X","X",".",".",".",".",7,"X",".","."],
# ["X",".",".","X",".",".","X","X",".","."],
# ["X",".",".",".","X",".","X","X",".","."],
# [".",".","X",".",".",".",".",".",".","."]]
sx,sy = getStart(field)
bfs(field,sx,sy,field[0][2])
matrix = []
while True:
row = input().split()
if len(row) == 1:
re_row = []
for char in row[0]:
if char.isdigit():
re_row.append(int(char))
else:
re_row.append(char)
matrix.append(re_row)
else:
matrix.append(row)
if len(matrix) == int(matrix[0][0]) + 1:
main()
break | a.cc:6:34: error: stray '#' in program
6 | search_field = field[1:] # cut the first [H,W,N] for min_path matrix
| ^
a.cc:28:49: error: stray '#' in program
28 | if field[ny][nx] == current[2]: # at the same cheese-power number
| ^
a.cc:29:49: error: stray '#' in program
29 | if field[ny][nx] == goal_N: # goal
| ^
a.cc:32:27: error: stray '#' in program
32 | else: # not goal, but could eat cheese
| ^
a.cc:44:7: error: invalid preprocessing directive #field
44 | # field = [[10,10,9],
| ^~~~~
a.cc:45:7: error: invalid preprocessing directive #[
45 | # [".","X",".",".",".","X",".","S",".","X"],
| ^
a.cc:46:7: error: invalid preprocessing directive #[
46 | # [6,".",".",5,"X",".",".","X",1,"X"],
| ^
a.cc:47:7: error: invalid preprocessing directive #[
47 | # [".",".",".","X","X","X","X",".",".","X"],
| ^
a.cc:48:7: error: invalid preprocessing directive #[
48 | # ["X",".",".",9,"X",".",".",".","X","."],
| ^
a.cc:49:7: error: invalid preprocessing directive #[
49 | # [8,".","X",2,"X",".",".","X",3,"X"],
| ^
a.cc:50:7: error: invalid preprocessing directive #[
50 | # [".",".",".","X","X",".","X",4,".","."],
| ^
a.cc:51:7: error: invalid preprocessing directive #[
51 | # ["X","X",".",".",".",".",7,"X",".","."],
| ^
a.cc:52:7: error: invalid preprocessing directive #[
52 | # ["X",".",".","X",".",".","X","X",".","."],
| ^
a.cc:53:7: error: invalid preprocessing directive #[
53 | # ["X",".",".",".","X",".","X","X",".","."],
| ^
a.cc:54:7: error: invalid preprocessing directive #[
54 | # [".",".","X",".",".",".",".",".",".","."]]
| ^
a.cc:1:1: error: 'import' does not name a type
1 | import sys
| ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
|
s087114440 | p00481 | C++ | #include<queue>
#include<cctype>
#include<cstdio>
#define mp make_pair
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int , int > pii;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int h,w;
char grid[1010][1010];
int sortestDestance(int sx,int sy,int gx,int gy)
{
static bool visited[1010][1010];
rep(i,h)rep(j,w) visited[i][j] = false;
visited[sy][sx] = true;
queue< pair< int ,pii > > qu;
qu.push(mp(0,mp(sy,sx)));
while(1)
{
pair<int ,pii> a = qu.front();
qu.pop();
int d = a.first,x = a.second.second,y = a.second.first;
if(x == gx && y == gy) return d;
rep(i,4)
{
int xx = x + dx[i], yy = y + dy[i];
if(0<=xx && xx<w && 0<=yy && yy<h && grid[yy][xx]!='X' && !visited[yy][xx])
{
visited[yy][xx]=true;
qu.push(mp(d+1,mp(yy,xx)));
}
}
}
}
int main(){
int n; scanf("%d%d%d",&h,&w,&n);
int cx[10],cy[10];
rep(i,h){
scanf("%s",grid[i]);
rep(j,w){
if(grid[i][j]=='S') cx[0]=j,cy[0]=i;
if(isdigit(grid[i][j])) cx[grid[i][j]-'0']=j,cy[grid[i][j]-'0']=i;
}
}
int cost=0;
rep(i,n) cost+=shortestDistance(cx[i],cy[i],cx[i+1],cy[i+1]);
printf("%d\n",cost);
return 0;
} | a.cc: In function 'int main()':
a.cc:60:23: error: 'shortestDistance' was not declared in this scope; did you mean 'sortestDestance'?
60 | rep(i,n) cost+=shortestDistance(cx[i],cy[i],cx[i+1],cy[i+1]);
| ^~~~~~~~~~~~~~~~
| sortestDestance
|
s452438257 | p00481 | C++ | #include <iostream>
#include <queue>
#include <tuple>
#include <string.h>
#define BLOCK -1
#define ROAD 0
#define GONE -2
void clear(std::queue<std::tuple<int, int, int, int*>> &q) {
while (!q.empty()) {
auto& item = q.front();
auto& map = std::get<int*>(item);
delete[] map;
q.pop();
}
}
int* copy(int* base, int size) {
int* copied = new int[size];
std::memcpy(copied, base, size);
return copied;
}
int main() {
int w, h, total;
std::cin >> h >> w >> total;
int* original = new int[w * h];
char temp;
int positionW = -1, positionH = -1;
for (int i = 0; i < w * h; i++) {
std::cin >> temp;
if (temp == 'S') {
positionW = i % w;
positionH = i / w;
original[i] = ROAD;
}
else if (temp == '.') {
original[i] = ROAD;
}
else if (temp == 'X') {
original[i] = BLOCK;
}
else {
original[i] = temp - '0';
}
}
int* first = new int[w * h];
std::memcpy(first, original, sizeof(int) * w * h);
int next = 1;
std::queue<std::tuple<int, int, int, int*>> queue;
queue.push(std::make_tuple(positionW, positionH, 0, first));
while (queue.size() != 0) {
auto item = queue.front();
queue.pop();
int posW = std::get<0>(item);
int posH = std::get<1>(item);
int step = std::get<2>(item);
int* map = std::get<3>(item);
if (posW < 0 || posW >= w || posH < 0 || posH >= h)
continue;
int current = map[posH * w + posW];
if (current == BLOCK || current == GONE) {
delete[] map;
continue;
}
map[posH * w + posW] = GONE;
if (current > 0 && current == next) {
next++;
clear(queue);
// if finished
if (next > total) {
std::cout << step << std::endl;
return 0;
}
std::memcpy(map, original, sizeof(int) * w * h);
map[posH * w + posW] = GONE;
}
step++;
queue.push(std::make_tuple(posW + 1, posH, step, copy(map, sizeof(int) * w * h)));
queue.push(std::make_tuple(posW - 1, posH, step, copy(map, sizeof(int) * w * h)));
queue.push(std::make_tuple(posW, posH + 1, step, copy(map, sizeof(int) * w * h)));
queue.push(std::make_tuple(posW, posH - 1, step, copy(map, sizeof(int) * w * h)));
delete[] map;
}
return 0;
} | a.cc: In function 'int* copy(int*, int)':
a.cc:21:14: error: 'memcpy' is not a member of 'std'; did you mean 'wmemcpy'?
21 | std::memcpy(copied, base, size);
| ^~~~~~
| wmemcpy
a.cc: In function 'int main()':
a.cc:51:14: error: 'memcpy' is not a member of 'std'; did you mean 'wmemcpy'?
51 | std::memcpy(first, original, sizeof(int) * w * h);
| ^~~~~~
| wmemcpy
a.cc:85:30: error: 'memcpy' is not a member of 'std'; did you mean 'wmemcpy'?
85 | std::memcpy(map, original, sizeof(int) * w * h);
| ^~~~~~
| wmemcpy
|
s698000109 | p00481 | C++ | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
int h, w, n;
string data[1100];
int main() {
while (cin >> h >> w >> n) {
rep(i, h) cin >> data[i];
pair<int, int> ce[10];
rep(i, h) rep(j, w) {
if (data[i][j] == 'S') {
ce[0] = pair<int, int>(i, j);
}
if (isdigit(data[i][j])) {
ce[data[i][j] - '0'] = pair<int, int>(i, j);
}
}
int sum = 0;
rep(i, n) {
int mp[1100][1100];
rep(i, 1100) rep(j, 1100) mp[i][j] = INF;
bool used[1100][1100] = {};
mp[ce[i].first][ce[i].second] = 0;
used[ce[i].first][ce[i].second] = true;
queue<pair<int, int>> que;
que.push(ce[i]);
while (que.size()) {
int y = que.front().first;
int x = que.front().second;
que.pop();
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
rep(i, 4) {
int ddy = y + dy[i];
int ddx = x + dx[i];
if (ddy >= 0 && ddy < h && ddx >= 0 && ddx < w &&
data[ddy][ddx] != 'X' && !used[ddy][ddx]) {
used[ddy][ddx] = true;
mp[ddy][ddx] = mp[y][x] + 1;
que.push(pair<int, int>(ddy, ddx));
}
}
}
sum += mp[ce[i + 1].first][ce[i + 1].second];
}
cout << sum << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:10:22: error: reference to 'data' is ambiguous
10 | rep(i, h) cin >> data[i];
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:14:11: error: reference to 'data' is ambiguous
14 | if (data[i][j] == 'S') {
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:17:19: error: reference to 'data' is ambiguous
17 | if (isdigit(data[i][j])) {
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:18:12: error: reference to 'data' is ambiguous
18 | ce[data[i][j] - '0'] = pair<int, int>(i, j);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:41:15: error: reference to 'data' is ambiguous
41 | data[ddy][ddx] != 'X' && !used[ddy][ddx]) {
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
|
s976607912 | p00481 | C++ | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
int h, w, n;
string data[1100];
int main() {
while (cin >> h >> w >> n) {
rep(i, h) cin >> data[i];
pair<int, int> ce[10];
rep(i, h) rep(j, w) {
if (data[i][j] == 'S') {
ce[0] = pair<int, int>(i, j);
}
if (isdigit(data[i][j])) {
ce[data[i][j] - '0'] = pair<int, int>(i, j);
}
}
int sum = 0;
rep(i, n) {
int mp[1100][1100];
rep(i, 1100) rep(j, 1100) mp[i][j] = INF;
bool used[1100][1100] = {};
mp[ce[i].first][ce[i].second] = 0;
used[ce[i].first][ce[i].second] = true;
queue<pair<int, int>> que;
que.push(ce[i]);
while (que.size()) {
int y = que.front().first;
int x = que.front().second;
que.pop();
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
rep(i, 4) {
int ddy = y + dy[i];
int ddx = x + dx[i];
if (ddy >= 0 && ddy < h && ddx >= 0 && ddx < w &&
data[ddy][ddx] != 'X' && !used[ddy][ddx]) {
used[ddy][ddx] = true;
mp[ddy][ddx] = mp[y][x] + 1;
que.push(pair<int, int>(ddy, ddx));
}
}
}
sum += mp[ce[i + 1].first][ce[i + 1].second];
}
cout << sum << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:10:22: error: reference to 'data' is ambiguous
10 | rep(i, h) cin >> data[i];
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:14:11: error: reference to 'data' is ambiguous
14 | if (data[i][j] == 'S') {
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:17:19: error: reference to 'data' is ambiguous
17 | if (isdigit(data[i][j])) {
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:18:12: error: reference to 'data' is ambiguous
18 | ce[data[i][j] - '0'] = pair<int, int>(i, j);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:41:15: error: reference to 'data' is ambiguous
41 | data[ddy][ddx] != 'X' && !used[ddy][ddx]) {
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
|
s151060240 | p00481 | C++ | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
int h, w, n;
string data[1100];
int main() {
while (cin >> h >> w >> n) {
rep(i, h) cin >> data[i];
pair<int, int> ce[10];
rep(i, h) rep(j, w) {
if (data[i][j] == 'S') {
ce[0] = pair<int, int>(i, j);
}
if (isdigit(data[i][j])) {
ce[data[i][j] - '0'] = pair<int, int>(i, j);
}
}
int sum = 0;
rep(i, n) {
int mp[1100][1100];
rep(i, 1100) rep(j, 1100) mp[i][j] = INF;
bool used[1100][1100] = {};
mp[ce[i].first][ce[i].second] = 0;
used[ce[i].first][ce[i].second] = true;
queue<pair<int, int>> que;
que.push(ce[i]);
while (que.size()) {
int y = que.front().first;
int x = que.front().second;
que.pop();
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
rep(i, 4) {
int ddy = y + dy[i];
int ddx = x + dx[i];
if (ddy >= 0 && ddy < h && ddx >= 0 && ddx < w &&
data[ddy][ddx] != 'X' && !used[ddy][ddx]) {
used[ddy][ddx] = true;
mp[ddy][ddx] = mp[y][x] + 1;
que.push(pair<int, int>(ddy, ddx));
}
}
}
sum += mp[ce[i + 1].first][ce[i + 1].second];
}
cout << sum << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:10:22: error: reference to 'data' is ambiguous
10 | rep(i, h) cin >> data[i];
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:13:11: error: reference to 'data' is ambiguous
13 | if (data[i][j] == 'S') {
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:16:19: error: reference to 'data' is ambiguous
16 | if (isdigit(data[i][j])) {
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:17:12: error: reference to 'data' is ambiguous
17 | ce[data[i][j] - '0'] = pair<int, int>(i, j);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
a.cc:40:15: error: reference to 'data' is ambiguous
40 | data[ddy][ddx] != 'X' && !used[ddy][ddx]) {
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'std::string data [1100]'
7 | string data[1100];
| ^~~~
|
s848011203 | p00481 | C++ | #include<bits/stdc++.h>
#define x first
#define y second
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;pair<int,int> p[12];bool t[1010][1010],v[1010][1010];queue<pair<int,pair<int,int> > >Q;int main(){int h,w,k,a=0,dx[]={0,1,0,-1},dy[]={1,0,-1,0};cin>>h>>w>>k;rep(i,0,h)rep(j,0,w){t[i][j]=true;char z;cin>>z;if(z=='X')t[i][j]=0;if(z=='S')p[0]=make_pair(i,j);if(z>'0'&&z<='9')p[z-'0']=make_pair(i,j);}rep(r,0,k){Q.push(make_pair(0,p[r]));rep(i,0,h)rep(j,0,w)v[i][j]=0;v[p[r].x][p[r].y]=1;while(1){int L=Q.front().x,Y=Q.front().y.x,X=Q.front().y.y;if(Y==p[r+1].x&&X==p[r+1].y){a+=L;break;}rep(i,0,4){int f=Y+dy[i],g=X+dx[i];if(f+1&&f<h&&g+1&&g<w)if(t[f][g]==1&&vis[f][g]==0)v[f][g]=1;Q.push(make_pair(L+1,make_pair(f,g)));}Q.pop();}while(!Q.empty())Q.pop();}cout<<a<<endl;return 0;} | a.cc: In function 'int main()':
a.cc:5:577: error: 'vis' was not declared in this scope
5 | using namespace std;pair<int,int> p[12];bool t[1010][1010],v[1010][1010];queue<pair<int,pair<int,int> > >Q;int main(){int h,w,k,a=0,dx[]={0,1,0,-1},dy[]={1,0,-1,0};cin>>h>>w>>k;rep(i,0,h)rep(j,0,w){t[i][j]=true;char z;cin>>z;if(z=='X')t[i][j]=0;if(z=='S')p[0]=make_pair(i,j);if(z>'0'&&z<='9')p[z-'0']=make_pair(i,j);}rep(r,0,k){Q.push(make_pair(0,p[r]));rep(i,0,h)rep(j,0,w)v[i][j]=0;v[p[r].x][p[r].y]=1;while(1){int L=Q.front().x,Y=Q.front().y.x,X=Q.front().y.y;if(Y==p[r+1].x&&X==p[r+1].y){a+=L;break;}rep(i,0,4){int f=Y+dy[i],g=X+dx[i];if(f+1&&f<h&&g+1&&g<w)if(t[f][g]==1&&vis[f][g]==0)v[f][g]=1;Q.push(make_pair(L+1,make_pair(f,g)));}Q.pop();}while(!Q.empty())Q.pop();}cout<<a<<endl;return 0;}
| ^~~
|
s845856684 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
struct Node{
int x,y;
};
const int max_n=1000+10;
int h,w,n,sx,sy,dx[]={0,0,-1,1},dy[]={-1,1,0,0},d[max_n][max_n],ans;
Node sN;
char c[max_n][max_n];
void bfs(int m){
if(m>n)return;
queue<Node> q;
memset(d,0,sizeof(d));
q.push(sN);
d[sN.x][sN.y]=1;
while(!q.empty()){
Node p=q.front();
q.pop();
if(c[p.x][p.y]=='0'+m){
ans+=d[p.x][p.y]-1;
sN.x=p.x;
sN.y=p.y;
bfs(m+1);
return;
}
for(int i=0;i<4;i++){
Node nN;
nN.x=p.x+dx[i];
nN.y=p.y+dy[i];
if(nN.x>=0 && nN.y<h
&& nN.y>=0 && nN.y<w
&& c[nN.x][nN.y]!='X' && !d[nN.x][nN.y]){
q.push(nN);
d[nN.x][nN.y]=d[p.x][p.y]+1;
}
}
}
}
int main(){
scanf("%d%d%d",&h,&w,&n);
for(int i=0;i<h;i++)
for(int j=0;j<w;j++){
cin>>c[i][j];
if(c[i][j]=='S'){sN.x=i;sN.y=j;}
}
bfs(1);
cout<<ans<<endl;
return 0;
} | a.cc: In function 'void bfs(int)':
a.cc:18:9: error: 'memset' was not declared in this scope
18 | memset(d,0,sizeof(d));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 | using namespace std;
|
s069635076 | p00481 | C++ | #include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
const ll INF = 1e9;
ll H, W, N;
vector<vector<ll>> F(10);
string M[1001];
ll dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
ll bfs(ll sx, ll sy, ll gx, ll gy) {
ll d[1001][1001];
queue<vector<ll>> que;
for(ll i = 0; i < H; i++) for (ll j = 0; j < W; j++) d[i][j] = INF;
que.push({sx, sy});
d[sy][sx] = 0;
while(que.size()) {
vector<ll> p = que.front(); que.pop();
if (p[0] == gx && p[1] == gy) break;
for (ll i = 0; i < 4; i++) {
ll nx = p[0] + dx[i], ny = p[1] + dy[i];
if (M[ny][nx] != 'X' && nx >= 0 && nx < W && ny >= 0 && ny < H && d[ny][nx] == INF) {
que.push({nx, ny});
d[ny][nx] = d[p[1]][p[0]] + 1;
}
}
}
return d[gy][gx];
}
ll main() {
ll ans = 0;
cin >> H >> W >> N;
for (ll i = 0; i < H; i++) {
cin >> M[i];
for (ll k = 0; k < W; k++) {
if (M[i][k] == 'S') {
F[0] = {k, i};
}
if (isdigit(M[i][k])) {
F[M[i][k] - '0'] = {k, i};
}
}
}
for (ll i = 0; i < N; i++) {
ans += bfs(F[i][0], F[i][1], F[i+1][0], F[i+1][1]);
}
cout << ans << endl;
return 0;
} | a.cc:42:1: error: '::main' must return 'int'
42 | ll main() {
| ^~
|
s085884935 | p00481 | C++ | #include<iostream>
#include<queue>
using namespace std;
typedef struct{
int x;
int y;
}P;
char graph[1000][1000];
P aim[10];
P s,g;//s?????????g??????
int N,W,H;
int vis[1000][1000];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int bfs(P s,P g);
int main(){
int i,j,t,step=0;
cin>>H>>W>>N;
for(i=0;i<H;i++)
for(j=0;j<W;j++){
cin>>graph[i][j];
if(graph[i][j]<='9'&&graph[i][j]>='1'){
t=graph[i][j]-'0';
aim[t].x=i;
aim[t].y=j;
}
else if(graph[i][j]=='S'){
s.x=i;
s.y=j;
graph[i][j]='.';
}
for(i=1;i<=N;i++){
g.x=aim[i].x;
g.y=aim[i].y;
step+=bfs(s,g);
s.x=g.x;
s.y=g.y;
graph[g.x][g.y]='.';
}
cout<<step<<endl;
}
int bfs(P s,P g){
queue<P> que;
P n;
for(int i=0;i<H;i++)
for(int j=0;j<W;j++)
vis[i][j]=-1;
que.push(s);
vis[s.x][s.y]=0;
while(que.size()){
P p=que.front();
que.pop();
if(p.x==g.x&&p.y==g.y)
break;
for(int i=0;i<4;i++){
n.x=p.x+dx[i];
n.y=p.y+dy[i];
if(0<=n.x&&n.x<H&&0<=n.y&&n.y<W&&graph[n.x][n.y]!='X'&&vis[n.x][n.y]==-1){
que.push(n);
vis[n.x][n.y]=vis[p.x][p.y]+1;
}
}
}
return vis[g.x][g.y];
} | a.cc: In function 'int main()':
a.cc:49:17: error: a function-definition is not allowed here before '{' token
49 | int bfs(P s,P g){
| ^
a.cc:77:2: error: expected '}' at end of input
77 | }
| ^
a.cc:19:11: note: to match this '{'
19 | int main(){
| ^
|
s439019501 | p00481 | C++ | #include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
typedef pair<int, int> P;
const int INF = 1<<10;
int H, W, N;
char field[1010][1010];
int dx[4] = {0,0,1,-1}, dy[4] = {1,-1,0,0};
int tim[1010][1010];
int sx, sy;
int cnt;
int hp = 1;
int bfs() {
for (int i = 1; i <= N; i++) {
bool flag = false;
queue<P> q;
for (int y = 0; y < H; y++)
for (int x = 0; x < W; x++) tim[y][x] = INF;
q.push(P(sx, sy));
tim[sy][sx] = 0;
while (!q.empty() && !flag) {
int x = q.front().first;
int y = q.front().second;
int c = tim[y][x];
q.pop();
for (int j = 0; j < 4; j++) {
int tx = x + dx[j], ty = y + dy[j];
if (tx < 0 || ty < 0 || tx >= W || ty >= H ||
tim[ty][tx] != INF || field[ty][tx] == 'X') continue;
if (field[ty][tx] == '0' + i) {
cnt += c + 1;
sx = tx; sy = ty;
flag = true;
break;
}
tim[ty][tx] = c + 1;
q.push(P(tx, ty));
}
}
}
}
int main() {
cin >> H >> W >> N;
for (int y = 0; y < H; y++) {
cin >> field[y];
for (int x = 0; x < W; x++) {
if (field[y][x] == 'S') {
sx = x; sy = y;
field[y][x] = '.';
}
}
} | a.cc: In function 'int bfs()':
a.cc:46:1: warning: no return statement in function returning non-void [-Wreturn-type]
46 | }
| ^
a.cc: In function 'int main()':
a.cc:58:4: error: expected '}' at end of input
58 | }
| ^
a.cc:48:12: note: to match this '{'
48 | int main() {
| ^
|
s705128241 | p00481 | C++ | #include<iostream>
#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
int mp[1002][1002],mp2[1002][1002];
int main()
{
????????char a;
????????int t, j, h, w, k, i;
????????pair<int, int> s, m[10];
????????queue<pair<int, int> > u;
????????queue<int> e;
????????cin >> h >> w >> k;
????????for (i = 0; i <= h; i++)
????????{
????????????????mp[i][0] = 1;
????????????????mp[i][w + 1] = 1;
????????????????mp2[i][0] = 1;
????????????????mp2[i][w + 1] = 1;
??
????????}
????????for (i = 0; i <= w; i++)
????????{
????????????????mp[0][i] = 1;
????????????????mp[h + 1][i] = 1;
????????????????mp2[0][i] = 1;
????????????????mp2[h + 1][i] = 1;
????????}
????????for (i = 1; i <= h; i++)
????????{
????????????????for (j = 1; j <= w; j++)
????????????????{
????????????????????????cin >> a;
????????????????????????if (a == 'X')
????????????????????????{
????????????????????????????????mp[i][j] = 1;
????????????????????????}
????????????????????????if (a == 'S')
????????????????????????{
????????????????????????????????mp[i][j] = 10;
????????????????????????????????s.first = i;
????????????????????????????????s.second = j;
????????????????????????}
????????????????????????if (a == '1')
????????????????????????{
????????????????????????????????mp[i][j] = 11;
????????????????????????????????m[1].first = i;
????????????????????????????????m[1].second = j;
????????????????????????}
????????????????????????if (a == '2')
????????????????????????{
????????????????????????????????mp[i][j] = 12;
????????????????????????????????m[2].first = i;
????????????????????????????????m[2].second = j;
????????????????????????}
????????????????????????if (a == '3')
????????????????????????{
????????????????????????????????mp[i][j] = 13;
????????????????????????????????m[3].first = i;
????????????????????????????????m[3].second = j;
????????????????????????}
????????????????????????if (a == '4')
????????????????????????{
????????????????????????????????mp[i][j] = 14;
????????????????????????????????m[4].first = i;
????????????????????????????????m[4].second = j;
????????????????????????}
????????????????????????if (a == '5')
????????????????????????{
????????????????????????????????mp[i][j] = 15;
????????????????????????????????m[5].first = i;
????????????????????????????????m[5].second = j;
????????????????????????}
????????????????????????if (a == '6')
????????????????????????{
????????????????????????????????mp[i][j] = 16;
????????????????????????????????m[6].first = i;
????????????????????????????????m[6].second = j;
????????????????????????}
????????????????????????if (a == '7')
????????????????????????{
????????????????????????????????mp[i][j] = 17;
????????????????????????????????m[7].first = i;
????????????????????????????????m[7].second = j;
????????????????????????}
????????????????????????if (a == '8')
????????????????????????{
????????????????????????????????mp[i][j] = 18;
????????????????????????????????m[8].first = i;
????????????????????????????????m[8].second = j;
????????????????????????}
????????????????????????if (a == '9')
????????????????????????{
????????????????????????????????mp[i][j] = 19;
????????????????????????????????m[9].first = i;
????????????????????????????????m[9].second = j;
????????????????????????}
????????????????}
????????}
????????t = 0;
????????e.push(0);
????????i = 1;
????????u.push(s);
????????while (i <= k)
????????{
????????????????t = e.front();
????????????????e.pop();
????????????????s = u.front();
????????????????u.pop();
????????????????if (s == m[i])
????????????????{
????????????????????????i++;
????????????????????????memset(mp2, 0, sizeof(mp2));
????????????????????????while (!u.empty())
????????????????????????{
????????????????????????????????u.pop();
????????????????????????}
????????????????????????while (!e.empty())
????????????????????????{
????????????????????????????????e.pop();
????????????????????????}
????????????????????????e.push(t);
????????????????????????u.push(s);
????????????????????????continue;
????????????????}
????????????????if (mp[s.first + 1][s.second] != 1 && mp2[s.first + 1][s.second] != 1)
????????????????{
????????????????????????mp2[s.first + 1][s.second] = 1;
????????????????????????s.first++;
????????????????????????u.push(s);
????????????????????????t++;
????????????????????????e.push(t);
????????????????????????t--;
????????????????????????s.first--;
????????????????}
????????????????if (mp[s.first][s.second + 1] != 1 && mp2[s.first][s.second + 1] != 1)
????????????????{
????????????????????????mp2[s.first][s.second + 1] = 1;
????????????????????????s.second++;
????????????????????????u.push(s);
????????????????????????t++;
????????????????????????e.push(t);
????????????????????????t--;
????????????????????????s.second--;
????????????????}
????????????????if (mp[s.first - 1][s.second] != 1 && mp2[s.first - 1][s.second] != 1)
????????????????{
????????????????????????mp2[s.first - 1][s.second] = 1;
????????????????????????s.first--;
????????????????????????u.push(s);
????????????????????????t++;
????????????????????????e.push(t);
????????????????????????t--;
????????????????????????s.first++;
????????????????}
????????????????if (mp[s.first][s.second - 1] != 1 && mp2[s.first][s.second - 1] != 1)
????????????????{
????????????????????????mp2[s.first][s.second - 1] = 1;
????????????????????????s.second--;
????????????????????????u.push(s);
????????????????????????t++;
????????????????????????e.push(t);
????????????????????????t--;
????????????????????????s.second++;
????????????????}
????????}
????????cout << t << endl;
????????return 0;
} | a.cc: In function 'int main()':
a.cc:9:1: error: expected primary-expression before '?' token
9 | ????????char a;
| ^
a.cc:9:2: error: expected primary-expression before '?' token
9 | ????????char a;
| ^
a.cc:9:3: error: expected primary-expression before '?' token
9 | ????????char a;
| ^
a.cc:9:4: error: expected primary-expression before '?' token
9 | ????????char a;
| ^
a.cc:9:5: error: expected primary-expression before '?' token
9 | ????????char a;
| ^
a.cc:9:6: error: expected primary-expression before '?' token
9 | ????????char a;
| ^
a.cc:9:7: error: expected primary-expression before '?' token
9 | ????????char a;
| ^
a.cc:9:8: error: expected primary-expression before '?' token
9 | ????????char a;
| ^
a.cc:9:9: error: expected primary-expression before 'char'
9 | ????????char a;
| ^~~~
a.cc:9:9: error: expected ':' before 'char'
9 | ????????char a;
| ^~~~
| :
a.cc:9:9: error: expected primary-expression before 'char'
9 | ????????char a;
| ^~~~
a.cc:9:9: error: expected ':' before 'char'
9 | ????????char a;
| ^~~~
| :
a.cc:9:9: error: expected primary-expression before 'char'
9 | ????????char a;
| ^~~~
a.cc:9:9: error: expected ':' before 'char'
9 | ????????char a;
| ^~~~
| :
a.cc:9:9: error: expected primary-expression before 'char'
9 | ????????char a;
| ^~~~
a.cc:9:9: error: expected ':' before 'char'
9 | ????????char a;
| ^~~~
| :
a.cc:9:9: error: expected primary-expression before 'char'
9 | ????????char a;
| ^~~~
a.cc:9:9: error: expected ':' before 'char'
9 | ????????char a;
| ^~~~
| :
a.cc:9:9: error: expected primary-expression before 'char'
9 | ????????char a;
| ^~~~
a.cc:9:9: error: expected ':' before 'char'
9 | ????????char a;
| ^~~~
| :
a.cc:9:9: error: expected primary-expression before 'char'
9 | ????????char a;
| ^~~~
a.cc:9:9: error: expected ':' before 'char'
9 | ????????char a;
| ^~~~
| :
a.cc:9:9: error: expected primary-expression before 'char'
9 | ????????char a;
| ^~~~
a.cc:9:9: error: expected ':' before 'char'
9 | ????????char a;
| ^~~~
| :
a.cc:9:9: error: expected primary-expression before 'char'
9 | ????????char a;
| ^~~~
a.cc:10:1: error: expected primary-expression before '?' token
10 | ????????int t, j, h, w, k, i;
| ^
a.cc:10:2: error: expected primary-expression before '?' token
10 | ????????int t, j, h, w, k, i;
| ^
a.cc:10:3: error: expected primary-expression before '?' token
10 | ????????int t, j, h, w, k, i;
| ^
a.cc:10:4: error: expected primary-expression before '?' token
10 | ????????int t, j, h, w, k, i;
| ^
a.cc:10:5: error: expected primary-expression before '?' token
10 | ????????int t, j, h, w, k, i;
| ^
a.cc:10:6: error: expected primary-expression before '?' token
10 | ????????int t, j, h, w, k, i;
| ^
a.cc:10:7: error: expected primary-expression before '?' token
10 | ????????int t, j, h, w, k, i;
| ^
a.cc:10:8: error: expected primary-expression before '?' token
10 | ????????int t, j, h, w, k, i;
| ^
a.cc:10:9: error: expected primary-expression before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
a.cc:10:9: error: expected ':' before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
| :
a.cc:10:9: error: expected primary-expression before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
a.cc:10:9: error: expected ':' before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
| :
a.cc:10:9: error: expected primary-expression before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
a.cc:10:9: error: expected ':' before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
| :
a.cc:10:9: error: expected primary-expression before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
a.cc:10:9: error: expected ':' before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
| :
a.cc:10:9: error: expected primary-expression before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
a.cc:10:9: error: expected ':' before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
| :
a.cc:10:9: error: expected primary-expression before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
a.cc:10:9: error: expected ':' before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
| :
a.cc:10:9: error: expected primary-expression before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
a.cc:10:9: error: expected ':' before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
| :
a.cc:10:9: error: expected primary-expression before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
a.cc:10:9: error: expected ':' before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
| :
a.cc:10:9: error: expected primary-expression before 'int'
10 | ????????int t, j, h, w, k, i;
| ^~~
a.cc:11:1: error: expected primary-expression before '?' token
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:2: error: expected primary-expression before '?' token
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:3: error: expected primary-expression before '?' token
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:4: error: expected primary-expression before '?' token
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:5: error: expected primary-expression before '?' token
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:6: error: expected primary-expression before '?' token
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:7: error: expected primary-expression before '?' token
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:8: error: expected primary-expression before '?' token
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:24: error: expected primary-expression before 's'
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:23: error: expected ':' before 's'
11 | ????????pair<int, int> s, m[10];
| ^~
| :
a.cc:11:24: error: 's' was not declared in this scope
11 | ????????pair<int, int> s, m[10];
| ^
a.cc:11:27: error: 'm' was not declared in this scope; did you mean 'tm'?
11 | ????????pair<int, int> s, m[10];
| ^
| tm
a.cc:11:32: error: expected ':' before ';' token
11 | ????????pair<int, int> s, m[10];
| ^
| :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
11 | ????????pair<int, int> s, m[10];
| ^
| :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
11 | ????????pair<int, int> s, m[10];
| ^
| :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
11 | ????????pair<int, int> s, m[10];
| ^
| :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
11 | ????????pair<int, int> s, m[10];
| ^
| :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
11 | ????????pair<int, int> s, m[10];
| ^
| :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
11 | ????????pair<int, int> s, m[10];
| ^
| :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:12:1: error: expected primary-expression before '?' token
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:2: error: expected primary-expression before '?' token
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:3: error: expected primary-expression before '?' token
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:4: error: expected primary-expression before '?' token
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:5: error: expected primary-expression before '?' token
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:6: error: expected primary-expression before '?' token
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:7: error: expected primary-expression before '?' token
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:8: error: expected primary-expression before '?' token
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:32: error: expected primary-expression before 'u'
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:31: error: expected ':' before 'u'
12 | ????????queue<pair<int, int> > u;
| ^~
| :
a.cc:12:32: error: 'u' was not declared in this scope
12 | ????????queue<pair<int, int> > u;
| ^
a.cc:12:33: error: expected ':' before ';' token
12 | ????????queue<pair<int, int> > u;
| |
s222640862 | p00481 | C++ | //
// 0558.cpp
//
//
// Created by Yoshida Satoshi on 2017/11/16.
//
//
#include <iostream>
#include <queue>
#include <utility>
#include <stdlib.h>
#define MAX 1000
#define INF 100000000
#define FOR(index,max) for(index=0;index<max;index++)
using namespace std;
typedef pair<int, int> P;
int main(){
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int nx,ny;
queue<P> que;
int H,W,N;
int state[MAX][MAX];//0:????????°or????????? -1:????????¶???
bool isVisited[MAX][MAX];
int d[MAX][MAX];
int ans=0;
P start[9];
P p;
char in;
cin>>H>>W>>N;
FOR(i,H){
FOR(j,W){
cin>>in;
if(in=='S'){
start[0](i,j);
state[i][j]=0;
}
else if(in=='X') state[i][j]=-1;
else if(in=='.') state[i][j]=0;
else{
state[i][j]=0;
start[atoi(in)](i,j);
}
}
}
FOR(k,N){
FOR(i,H){
FOR(j,W){
isVisited[i][j]=false;
d[i][j]=INF;
}
}
que.push(start[k]);
d[start[k].first][start[k].second]=0;
while(que.size()){
p=que.front();
que.pop();
if(p==start[k+1]) break;
FOR(l,4){
nx=p.first+dx[l];
ny=p.seond+dy[i];
if(!(nx<0||ny<0||nx>H-1||ny>W-1||state[nx][ny]==-1||d[nx][ny]==INF)){
que.push(P(nx,ny));
d[nx][ny]=d[p.first][p.second]+1;
}
}
}
ans += d[start[k+1].first][start[k+1].second];
}
cout<<ans<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:38:9: error: 'i' was not declared in this scope; did you mean 'in'?
38 | FOR(i,H){
| ^
a.cc:16:28: note: in definition of macro 'FOR'
16 | #define FOR(index,max) for(index=0;index<max;index++)
| ^~~~~
a.cc:39:13: error: 'j' was not declared in this scope
39 | FOR(j,W){
| ^
a.cc:16:28: note: in definition of macro 'FOR'
16 | #define FOR(index,max) for(index=0;index<max;index++)
| ^~~~~
a.cc:49:28: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
49 | start[atoi(in)](i,j);
| ^~
| |
| char
In file included from /usr/include/c++/14/cstdlib:79,
from /usr/include/c++/14/ext/string_conversions.h:43,
from /usr/include/c++/14/bits/basic_string.h:4154,
from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:9:
/usr/include/stdlib.h:105:30: note: initializing argument 1 of 'int atoi(const char*)'
105 | extern int atoi (const char *__nptr)
| ~~~~~~~~~~~~^~~~~~
a.cc:55:9: error: 'k' was not declared in this scope
55 | FOR(k,N){
| ^
a.cc:16:28: note: in definition of macro 'FOR'
16 | #define FOR(index,max) for(index=0;index<max;index++)
| ^~~~~
a.cc:56:13: error: 'i' was not declared in this scope; did you mean 'in'?
56 | FOR(i,H){
| ^
a.cc:16:28: note: in definition of macro 'FOR'
16 | #define FOR(index,max) for(index=0;index<max;index++)
| ^~~~~
a.cc:57:17: error: 'j' was not declared in this scope
57 | FOR(j,W){
| ^
a.cc:16:28: note: in definition of macro 'FOR'
16 | #define FOR(index,max) for(index=0;index<max;index++)
| ^~~~~
a.cc:70:17: error: 'l' was not declared in this scope
70 | FOR(l,4){
| ^
a.cc:16:28: note: in definition of macro 'FOR'
16 | #define FOR(index,max) for(index=0;index<max;index++)
| ^~~~~
a.cc:72:22: error: 'P' {aka 'struct std::pair<int, int>'} has no member named 'seond'; did you mean 'second'?
72 | ny=p.seond+dy[i];
| ^~~~~
| second
a.cc:72:31: error: 'i' was not declared in this scope; did you mean 'in'?
72 | ny=p.seond+dy[i];
| ^
| in
|
s917838533 | p00481 | C++ | //
// 0558.cpp
//
//
// Created by Yoshida Satoshi on 2017/11/16.
//
//
#include <iostream>
#include <queue>
#include <utility>
#include <stdlib.h>
#define MAX 1000
#define INF 100000000
#define FOR(index,max) for(int index=0;index<max;index++)
using namespace std;
typedef pair<int, int> P;
int main(){
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int nx,ny;
queue<P> que;
int H,W,N;
int state[MAX][MAX];//0:????????°or????????? -1:????????¶???
bool isVisited[MAX][MAX];
int d[MAX][MAX];
int ans=0;
P start[9];
P p;
char in;
cin>>H>>W>>N;
FOR(i,H){
FOR(j,W){
cin>>in;
if(in=='S'){
start[0].first=i;
start[0].second=j;
state[i][j]=0;
}
else if(in=='X') state[i][j]=-1;
else if(in=='.') state[i][j]=0;
else{
state[i][j]=0;
start[atoi(in)].first=i;
start[atoi(in)].second=j;
}
}
}
FOR(k,N){
FOR(i,H){
FOR(j,W){
isVisited[i][j]=false;
d[i][j]=INF;
}
}
que.push(start[k]);
d[start[k].first][start[k].second]=0;
while(que.size()){
p=que.front();
que.pop();
if(p==start[k+1]) break;
FOR(l,4){
nx=p.first+dx[l];
ny=p.seond+dy[i];
if(!(nx<0||ny<0||nx>H-1||ny>W-1||state[nx][ny]==-1||d[nx][ny]==INF)){
que.push(P(nx,ny));
d[nx][ny]=d[p.first][p.second]+1;
}
}
}
ans += d[start[k+1].first][start[k+1].second];
}
cout<<ans<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:50:28: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
50 | start[atoi(in)].first=i;
| ^~
| |
| char
In file included from /usr/include/c++/14/cstdlib:79,
from /usr/include/c++/14/ext/string_conversions.h:43,
from /usr/include/c++/14/bits/basic_string.h:4154,
from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:9:
/usr/include/stdlib.h:105:30: note: initializing argument 1 of 'int atoi(const char*)'
105 | extern int atoi (const char *__nptr)
| ~~~~~~~~~~~~^~~~~~
a.cc:51:28: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
51 | start[atoi(in)].second=j;
| ^~
| |
| char
/usr/include/stdlib.h:105:30: note: initializing argument 1 of 'int atoi(const char*)'
105 | extern int atoi (const char *__nptr)
| ~~~~~~~~~~~~^~~~~~
a.cc:74:22: error: 'P' {aka 'struct std::pair<int, int>'} has no member named 'seond'; did you mean 'second'?
74 | ny=p.seond+dy[i];
| ^~~~~
| second
a.cc:74:31: error: 'i' was not declared in this scope
74 | ny=p.seond+dy[i];
| ^
|
s044766364 | p00481 | C++ | //
// 0558.cpp
//
//
// Created by Yoshida Satoshi on 2017/11/16.
//
//
#include <iostream>
#include <queue>
#include <utility>
#include <stdlib.h>
#define MAX 1000
#define INF 100000000
#define FOR(index,max) for(int index=0;index<max;index++)
using namespace std;
typedef pair<int, int> P;
int main(){
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int nx,ny;
queue<P> que;
int H,W,N;
int state[MAX][MAX];//0:????????°or????????? -1:????????¶???
bool isVisited[MAX][MAX];
int d[MAX][MAX];
int ans=0;
int sx[9];
int sy[9];
P p;
char in;
cin>>H>>W>>N;
FOR(i,H){
FOR(j,W){
cin>>in;
if(in=='S'){
sx[0]=i;
sy[0]=j;
state[i][j]=0;
}
else if(in=='X') state[i][j]=-1;
else if(in=='.') state[i][j]=0;
else{
state[i][j]=0;
sx[atoi(in)]=i;
sy[atoi(in)]=j;
}
}
}
FOR(k,N){
FOR(i,H){
FOR(j,W){
isVisited[i][j]=false;
d[i][j]=INF;
}
}
que.push(P(sx[k],sy[k]));
d[sx[k]][sy[k]]=0;
while(que.size()){
p=que.front();
que.pop();
if(p==P(sx[k+1],sy[k+1])) break;
FOR(l,4){
nx=p.first+dx[l];
ny=p.seond+dy[i];
if(!(nx<0||ny<0||nx>H-1||ny>W-1||state[nx][ny]==-1||d[nx][ny]==INF)){
que.push(P(nx,ny));
d[nx][ny]=d[p.first][p.second]+1;
}
}
}
ans += d[start[k+1].first][start[k+1].second];
}
cout<<ans<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:51:25: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
51 | sx[atoi(in)]=i;
| ^~
| |
| char
In file included from /usr/include/c++/14/cstdlib:79,
from /usr/include/c++/14/ext/string_conversions.h:43,
from /usr/include/c++/14/bits/basic_string.h:4154,
from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:9:
/usr/include/stdlib.h:105:30: note: initializing argument 1 of 'int atoi(const char*)'
105 | extern int atoi (const char *__nptr)
| ~~~~~~~~~~~~^~~~~~
a.cc:52:25: error: invalid conversion from 'char' to 'const char*' [-fpermissive]
52 | sy[atoi(in)]=j;
| ^~
| |
| char
/usr/include/stdlib.h:105:30: note: initializing argument 1 of 'int atoi(const char*)'
105 | extern int atoi (const char *__nptr)
| ~~~~~~~~~~~~^~~~~~
a.cc:75:22: error: 'P' {aka 'struct std::pair<int, int>'} has no member named 'seond'; did you mean 'second'?
75 | ny=p.seond+dy[i];
| ^~~~~
| second
a.cc:75:31: error: 'i' was not declared in this scope
75 | ny=p.seond+dy[i];
| ^
a.cc:84:18: error: 'start' was not declared in this scope
84 | ans += d[start[k+1].first][start[k+1].second];
| ^~~~~
|
s364234976 | p00481 | C++ | //
// 0558.cpp
//
//
// Created by Yoshida Satoshi on 2017/11/16.
//
//
#include <iostream>
#include <queue>
#include <utility>
#include <stdlib.h>
#define MAX 1000
#define INF 100000000
#define FOR(index,max) for(int index=0;index<max;index++)
using namespace std;
typedef pair<int, int> P;
int main(){
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int nx,ny;
queue<P> que;
int H,W,N;
int state[MAX][MAX];//0:????????°or????????? -1:????????¶???
bool isVisited[MAX][MAX];
int d[MAX][MAX];
int ans=0;
int sx[9];
int sy[9];
P p;
char in;
cin>>H>>W>>N;
FOR(i,H){
FOR(j,W){
cin>>in;
if(in=='S'){
sx[0]=i;
sy[0]=j;
state[i][j]=0;
}
else if(in=='X') state[i][j]=-1;
else if(in=='.') state[i][j]=0;
else{
state[i][j]=0;
sx[in-'0']=i;
sy[in-'0']=j;
}
}
}
FOR(k,N){
FOR(i,H){
FOR(j,W){
isVisited[i][j]=false;
d[i][j]=INF;
}
}
que.push(P(sx[k],sy[k]));
d[sx[k]][sy[k]]=0;
while(que.size()){
p=que.front();
que.pop();
if(p==P(sx[k+1],sy[k+1])) break;
FOR(l,4){
nx=p.first+dx[l];
ny=p.seond+dy[i];
if(!(nx<0||ny<0||nx>H-1||ny>W-1||state[nx][ny]==-1||d[nx][ny]==INF)){
que.push(P(nx,ny));
d[nx][ny]=d[p.first][p.second]+1;
}
}
}
ans += d[start[k+1].first][start[k+1].second];
}
cout<<ans<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:75:22: error: 'P' {aka 'struct std::pair<int, int>'} has no member named 'seond'; did you mean 'second'?
75 | ny=p.seond+dy[i];
| ^~~~~
| second
a.cc:75:31: error: 'i' was not declared in this scope
75 | ny=p.seond+dy[i];
| ^
a.cc:84:18: error: 'start' was not declared in this scope
84 | ans += d[start[k+1].first][start[k+1].second];
| ^~~~~
|
s664660681 | p00481 | C++ | //
// 0558.cpp
//
//
// Created by Yoshida Satoshi on 2017/11/16.
//
//
#include <iostream>
#include <queue>
#include <utility>
#include <stdlib.h>
#define MAX 1000
#define INF 100000000
#define FOR(index,max) for(int index=0;index<max;index++)
using namespace std;
typedef pair<int, int> P;
int main(){
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int nx,ny;
queue<P> que;
int H,W,N;
int state[MAX][MAX];//0:????????°or????????? -1:????????¶???
bool isVisited[MAX][MAX];
int d[MAX][MAX];
int ans=0;
int sx[9];
int sy[9];
P p;
char in;
cin>>H>>W>>N;
FOR(i,H){
FOR(j,W){
cin>>in;
if(in=='S'){
sx[0]=i;
sy[0]=j;
state[i][j]=0;
}
else if(in=='X') state[i][j]=-1;
else if(in=='.') state[i][j]=0;
else{
state[i][j]=0;
sx[in-'0']=i;
sy[in-'0']=j;
}
}
}
FOR(k,N){
FOR(i,H){
FOR(j,W){
isVisited[i][j]=false;
d[i][j]=INF;
}
}
que.push(P(sx[k],sy[k]));
d[sx[k]][sy[k]]=0;
while(que.size()){
p=que.front();
que.pop();
if(p==P(sx[k+1],sy[k+1])) break;
FOR(l,4){
nx=p.first+dx[l];
ny=p.second+dy[l];
if(!(nx<0||ny<0||nx>H-1||ny>W-1||state[nx][ny]==-1||d[nx][ny]==INF)){
que.push(P(nx,ny));
d[nx][ny]=d[p.first][p.second]+1;
}
}
}
ans += d[start[k+1].first][start[k+1].second];
}
cout<<ans<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:84:18: error: 'start' was not declared in this scope
84 | ans += d[start[k+1].first][start[k+1].second];
| ^~~~~
|
s041408842 | p00481 | C++ | //
// 0558.cpp
//
//
// Created by Yoshida Satoshi on 2017/11/16.
//
//
#include <iostream>
#include <queue>
#include <utility>
#include <stdlib.h>
#define MAX 1000
#define INF 100000000
#define FOR(index,max) for(int index=0;index<max;index++)
using namespace std;
typedef pair<int, int> P;
int ctoi(char c){
switch(c){
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default : return -1;
}
}
int main(){
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int nx,ny;
queue<P> que;
int H,W,N;
int state[MAX][MAX];//0:????????°or????????? -1:????????¶???
int d[MAX][MAX];
int ans=0;
int sx[9];
int sy[9];
P p;
char in;
cin>>H>>W>>N;
FOR(i,H){
FOR(j,W){
cin>>in;
if(in=='S'){
sx[0]=i;
sy[0]=j;
state[i][j]=0;
}
else if(in=='X') state[i][j]=-1;
else if(in=='.') state[i][j]=0;
else{
state[i][j]=0;
sx[ctoi(in)]=i;
sy[ctoi(in)]=j;
}
}
}
FOR(k,N){
FOR(i,H){
FOR(j,W){
isVisited[i][j]=false;
d[i][j]=INF;
}
}
que.push(P(sx[k],sy[k]));
d[sx[k]][sy[k]]=0;
while(que.size()){
p=que.front();
que.pop();
if(p==P(sx[k+1],sy[k+1])) break;
FOR(l,4){
nx=p.first+dx[l];
ny=p.second+dy[l];
if(!(nx<0||ny<0||nx>H-1||ny>W-1||state[nx][ny]==-1||d[nx][ny]==INF)){
que.push(P(nx,ny));
d[nx][ny]=d[p.first][p.second]+1;
}
}
}
ans += d[sx[k+1]][sy[k+1]];
}
cout<<ans<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:76:17: error: 'isVisited' was not declared in this scope
76 | isVisited[i][j]=false;
| ^~~~~~~~~
|
s377636804 | p00481 | C++ | #include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////
struct S{
int num;
int x;
int y;
};
int main(){
int h,w,n;
C3(h,w,n);
int f[h][w] = {};
pair<int,int> g[n+1];
pair<int,int> s[n+1];
rep(i,0,h){
rep(j,0,w){
char c;
cin >> c;
if(c == 'X'){
f[i][j] = -1;
}
else if(c == '.'){
f[i][j] = 0;
}
else if(c == 'S'){
pair<int,int> tt = {j,i};
s[1] = tt;
}
else{
int t = c - '0';
f[i][j] = t;
pair<int,int> tt = {j,i};
g[t] = tt;
if(t < n){
s[t+1] = tt;
}
}
}
}
int ans = 0;
rep(i,1,n+1){
int sx = s[i].first;
int sy = s[i].second;
int gx = g[i].first;
int gy = g[i].second;
//printf("sx:%d sy:%d gx:%d gy:%d\n",sx,sy,gx,gy);
queue<struct S> q;
struct S tmp = {0,sx,sy};
q.push(tmp);
int fNum[h][w];
rep(i,0,h)
rep(j,0,w)
fNum[i][j] = 0xFFFF;
while(!q.empty()){
struct S s = q.front();
//printf("i:%d n:%d x:%d y:%d\n",i,s.num,s.x,s.y);
q.pop();
if(f[s.y][s.x] == -1){
continue;
}
if(s.num >= fNum[s.y][s.x] && s.num != 0)
continue;
fNum[s.y][s.x] = s.num;
if(s.y == gy && s.x == gx)
continue;
else{
if(s.y > 0){
if(f[s.y-1][s.x] != -1&& fNum[s.y-1][s.x] > s.num+1){
struct S t = {s.num+1,s.x,s.y-1};
q.push(t);
}
}
if(s.x + 1 <= w - 1 ){
if(f[s.y][s.x+1] != -1 && fNum[s.y][s.x+1] > s.num+1){
struct S r = {s.num+1,s.x+1,s.y};
q.push(r);
}
}
if(s.x > 0){
if(f[s.y][s.x-1] != -1 && fNum[s.y][s.x-1] > s.num+1){
struct S l = {s.num+1,s.x-1,s.y};
q.push(l);
}
}
if(s.y + 1 <= h -1 ){
if(f[s.y+1][s.x] != -1 && fNum[s.y+1][s.x] > s.num+1){
struct S #include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////
struct S{
int num;
int x;
int y;
};
int main(){
int h,w,n;
C3(h,w,n);
int f[h][w] = {};
pair<int,int> g[n+1];
pair<int,int> s[n+1];
rep(i,0,h){
rep(j,0,w){
char c;
cin >> c;
if(c == 'X'){
f[i][j] = -1;
}
else if(c == '.'){
f[i][j] = 0;
}
else if(c == 'S'){
pair<int,int> tt = {j,i};
s[1] = tt;
}
else{
int t = c - '0';
f[i][j] = t;
pair<int,int> tt = {j,i};
g[t] = tt;
if(t < n){
s[t+1] = tt;
}
}
}
}
int ans = 0;
rep(i,1,n+1){
int sx = s[i].first;
int sy = s[i].second;
int gx = g[i].first;
int gy = g[i].second;
//printf("sx:%d sy:%d gx:%d gy:%d\n",sx,sy,gx,gy);
queue<struct S> q;
struct S tmp = {0,sx,sy};
q.push(tmp);
int fNum[h][w];
rep(i,0,h)
rep(j,0,w)
fNum[i][j] = 0xFFFF;
while(!q.empty()){
struct S s = q.front();
//printf("i:%d n:%d x:%d y:%d\n",i,s.num,s.x,s.y);
q.pop();
if(f[s.y][s.x] == -1){
continue;
}
if(s.num >= fNum[s.y][s.x] && s.num != 0)
continue;
fNum[s.y][s.x] = s.num;
if(s.y == gy && s.x == gx)
continue;
else{
if(s.y > 0){
if(f[s.y-1][s.x] != -1&& fNum[s.y-1][s.x] > s.num+1){
struct S t = {s.num+1,s.x,s.y-1};
q.push(t);
}
}
if(s.x + 1 <= w - 1 ){
if(f[s.y][s.x+1] != -1 && fNum[s.y][s.x+1] > s.num+1){
struct S r = {s.num+1,s.x+1,s.y};
q.push(r);
}
}
if(s.x > 0){
if(f[s.y][s.x-1] != -1 && fNum[s.y][s.x-1] > s.num+1){
struct S l = {s.num+1,s.x-1,s.y};
q.push(l);
}
}
if(s.y + 1 <= h -1 ){
if(f[s.y+1][s.x] != -1 && fNum[s.y+1][s.x] > s.num+1){
struct S b = {s.num+1,s.x,s.y+1};
q.push(b);
}
}
}
}
ans += fNum[gy][gx];
}
P(ans);
ret 0;
}b = {s.num+1,s.x,s.y+1};
q.push(b);
}
}
}
}
ans += fNum[gy][gx];
}
P(ans);
ret 0;
} | a.cc:125:22: error: stray '#' in program
125 | struct S #include<iostream>
| ^
a.cc: In function 'int main()':
a.cc:125:30: error: expected initializer before '<' token
125 | struct S #include<iostream>
| ^
a.cc:162:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
162 | int main(){
| ^~
a.cc:162:9: note: remove parentheses to default-initialize a variable
162 | int main(){
| ^~
| --
a.cc:162:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:162:11: error: a function-definition is not allowed here before '{' token
162 | int main(){
| ^
a.cc:262:2: error: 'b' was not declared in this scope
262 | }b = {s.num+1,s.x,s.y+1};
| ^
|
s287415089 | p00481 | C++ | #include <iostream>
#include <queue>
using namespace std;
int h,w,n;
int en;//energy indicates which cheese to eat next
const int MAX_N=1000;
char map[MAX_N][MAX_N];
struct point{
int x,y;
int step;
point(int xx, int yy, int ss){
x=xx;
y=yy;
step=ss;
}
};
struct point p[10];
int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1};
int ok(int x, int y){
if(x>=0 && x<h && y>=0 && y<w) return 1;
return 0;
}
int bfs(int next){
int nextcheese = next +1; int res=0;
queue<point> q;
point cur(p[next].x, p[next].y,0);
q.push(cur);
while(q.size()){
cur = q.front(); q.pop();
int x=cur.x, y=cur.y;
int nx, ny;
for(int i=0; i<4; i++){
nx = x+dx[i]; ny=y+dy[i];
if(ok(nx, ny)){
if((map[nx][ny]-'0')==nextcheese) return ++cur.step;
if(map[nx][ny]=='.'){
point temp(nx, ny, cur.step+1);
q.push(temp);
}
}
}
}
}
void solve(){
int sx, sy;
scanf("%d%d%d", &h, &w, &n);
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
cin>>ch; map[i][j]=ch;
switch(ch){
case '.': break;
case 'X': break;
case 'S': p[0].x = i; p[0].y = j; break;
default:
int t=ch-'0';
p[t].x = i; p[t].y = j;
}
}
}
int step=0;
for(int i=0; i<n; i++){
step+=bfs(i);
}
printf("%d", step);
}
int main(){
solve();
}
| a.cc:18:18: error: no matching function for call to 'point::point()'
18 | struct point p[10];
| ^
a.cc:12:5: note: candidate: 'point::point(int, int, int)'
12 | point(int xx, int yy, int ss){
| ^~~~~
a.cc:12:5: note: candidate expects 3 arguments, 0 provided
a.cc:9:8: note: candidate: 'constexpr point::point(const point&)'
9 | struct point{
| ^~~~~
a.cc:9:8: note: candidate expects 1 argument, 0 provided
a.cc:9:8: note: candidate: 'constexpr point::point(point&&)'
a.cc:9:8: note: candidate expects 1 argument, 0 provided
a.cc: In function 'void solve()':
a.cc:54:18: error: 'ch' was not declared in this scope; did you mean 'h'?
54 | cin>>ch; map[i][j]=ch;
| ^~
| h
a.cc: In function 'int bfs(int)':
a.cc:47:1: warning: control reaches end of non-void function [-Wreturn-type]
47 | }
| ^
|
s746003386 | p00481 | C++ | #include <cstdio>
#include <queue>
using namespace std;
int h, w, n;
const int MAX_N = 1000;
char map[MAX_N][MAX_N];
struct point{
int x, y;
int step;
point(){
x = 0; y = 0; step = 0;
}
point(int xx, int yy, int ss){
x = xx;
y = yy;
step = ss;
}
};
struct point p[10];
int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
int ok(int x, int y){
if (x >= 0 && x<h && y >= 0 && y<w) return 1;
return 0;
}
int bfs(int next){
int nextcheese = next + 1; int res = 0;
queue<point> q;
point cur(p[next].x, p[next].y, 0);
q.push(cur);
while (q.size()){
cur = q.front(); q.pop();
int x = cur.x, y = cur.y;
int nx, ny;
for (int i = 0; i<4; i++){
nx = x + dx[i]; ny = y + dy[i];
if (ok(nx, ny)){
if ((map[nx][ny] - '0') == nextcheese) return ++cur.step;
if (map[nx][ny] == '.'){
point temp(nx, ny, cur.step + 1);
q.push(temp);
}
}
}
}
}
void solve(){
int sx, sy;
scanf("%d%d%d", &h, &w, &n);
for (int i = 0; i<h; i++){
for (int j = 0; j<w; j++){
char ch;
cin >> ch; map[i][j] = ch;
switch (ch){
case '.': break;
case 'X': break;
case 'S': p[0].x = i; p[0].y = j; break;
default:
int t = ch - '0';
p[t].x = i; p[t].y = j;
}
}
}
int step = 0;
for (int i = 0; i<n; i++){
step += bfs(i);
}
printf("%d", step);
}
int main(){
solve();
}
| a.cc: In function 'void solve()':
a.cc:57:25: error: 'cin' was not declared in this scope
57 | cin >> ch; map[i][j] = ch;
| ^~~
a.cc:3:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
2 | #include <queue>
+++ |+#include <iostream>
3 | using namespace std;
a.cc: In function 'int bfs(int)':
a.cc:49:1: warning: control reaches end of non-void function [-Wreturn-type]
49 | }
| ^
|
s705560840 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int h,w,n;
int en;//energy indicates which cheese to eat next
const int MAX_N=1000;
char map[MAX_N][MAX_N];
struct point{
int x,y;
int step;
point(int xx, int yy, int ss){
x=xx;
y=yy;
step=ss;
}
};
struct point p[10];
int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1};
int ok(int x, int y){
if(x>=0 && x<h && y>=0 && y<w) return 1;
return 0;
}
int bfs(int next){
int nextcheese = next +1; int res=0;
queue<point> q;
point cur(p[next].x, p[next].y,0);
q.push(cur);
while(q.size()){
cur = q.front(); q.pop();
int x=cur.x, y=cur.y;
int nx, ny;
for(int i=0; i<4; i++){
nx = x+dx[i]; ny=y+dy[i];
if(ok(nx, ny)){
if((map[nx][ny]-'0')==nextcheese) return ++cur.step;
if(map[nx][ny]=='.'){
point temp(nx, ny, cur.step+1);
q.push(temp);
}
}
}
}
}
void solve(){
int sx, sy;
scanf("%d%d%d", &h, &w, &n);
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
char ch;
cin>>ch; map[i][j]=ch;
switch(ch){
case '.': break;
case 'X': break;
case 'S': p[0].x = i; p[0].y = j; break;
default:
int t=ch-'0';
p[t].x = i; p[t].y = j;
}
}
}
int step=0;
for(int i=0; i<n; i++){
step+=bfs(i);
}
printf("%d\n", step);
}
int main(){
solve();
}
| a.cc:19:18: error: no matching function for call to 'point::point()'
19 | struct point p[10];
| ^
a.cc:13:5: note: candidate: 'point::point(int, int, int)'
13 | point(int xx, int yy, int ss){
| ^~~~~
a.cc:13:5: note: candidate expects 3 arguments, 0 provided
a.cc:10:8: note: candidate: 'constexpr point::point(const point&)'
10 | struct point{
| ^~~~~
a.cc:10:8: note: candidate expects 1 argument, 0 provided
a.cc:10:8: note: candidate: 'constexpr point::point(point&&)'
a.cc:10:8: note: candidate expects 1 argument, 0 provided
a.cc: In function 'int bfs(int)':
a.cc:48:1: warning: control reaches end of non-void function [-Wreturn-type]
48 | }
| ^
|
s873460133 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int h,w,n;
const int MAX_N=1005;
char map[MAX_N][MAX_N];
struct point{
int x,y;
int step;
point(){
x=0; y=0; step=0;
}
point(int xx, int yy, int ss){
x=xx;
y=yy;
step=ss;
}
};
struct point p[16];
int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1};
int ok(int x, int y){
if(x>=0 && x<h && y>=0 && y<w) return 1;
return 0;
}
int bfs(int next){
int nextcheese = next +1;
queue<point> q;
point cur(p[next].x, p[next].y,0);
q.push(cur);
while(q.size()){
cur = q.front(); q.pop();
int x=cur.x, y=cur.y;
int nx, ny;
for(int i=0; i<4; i++){
nx = x+dx[i]; ny=y+dy[i];
if(ok(nx, ny)){
if((map[nx][ny]-'0')==nextcheese) return ++cur.step;
if(map[nx][ny]=='.'){
point temp(nx, ny, cur.step+1);
q.push(temp);
}
}
}
}
}
void solve(){
cin>>h>>w>>n;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
cin>>map[i][j]
}
}
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
char ch=map[i][j];
switch(ch){
case '.': break;
case 'X': break;
case 'S': p[0].x = i; p[0].y = j; map[i][j]='.';break;
default:
int t=(ch-'0');
p[t].x = i; p[t].y = j;
}
}
}
int step=0;
for(int i=0; i<n; i++){
step+=bfs(i);
}
printf("%d\n", step);
}
int main(){
solve();
}
| a.cc: In function 'void solve()':
a.cc:57:27: error: expected ';' before '}' token
57 | cin>>map[i][j]
| ^
| ;
58 | }
| ~
a.cc: In function 'int bfs(int)':
a.cc:51:1: warning: control reaches end of non-void function [-Wreturn-type]
51 | }
| ^
|
s672446017 | p00481 | C++ | #include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int h,w,n;
const int MAX_N=1005;
char map[MAX_N][MAX_N];
int visit[MAX_N][MAX_N];
struct point{
int x,y;
int step;
point(){
x=0; y=0; step=0;
}
point(int xx, int yy, int ss){
x=xx;
y=yy;
step=ss;
}
};
struct point p[16];
int dx[4]={-1,0,1,0}, dy[4]={0,1,0,-1};
int ok(int x, int y){
if(x>=0 && x<h && y>=0 && y<w) return 1;
return 0;
}
int bfs(int next){
for(int i=0; i<MAX_N; i++){
for(int j=0; j<MAX_N;j++){
visit[i][j]==0;
}
}
int nextcheese = next +1;
queue<point> q;
point cur(p[next].x, p[next].y,0);
q.push(cur);
while(q.size()){
cur = q.front(); q.pop();
int x=cur.x, y=cur.y;
int nx, ny;
for(int i=0; i<4; i++){
nx = x+dx[i]; ny=y+dy[i];
if(ok(nx, ny)){
if((map[nx][ny]-'0')==nextcheese) return ++cur.step;
if((map[nx][ny]=='.')&&visit[nx][ny]==0){
q.push(point(nx, ny, cur.step+1));
visit[nx][ny]=1;
}
}
}
}
}
void solve(){
cin>>h>>w>>n;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
cin>>map[i][j];
}
}
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
char ch=map[i][j];
switch(ch){
case '.': break;
case 'X': break;
case 'S': p[0].x = i; p[0].y = j; map[i][j]='.';break;
default:
int t=(ch-'0');
p[t].x = i; p[t].y = j;
}
/* if(map[i][j]=='S'){
p[0].x=i; p[0].y = j;
map[i][j]='.';
}
else if(isdigit(map[i][j])){
int index=map[i][j]-'0';
p[index].x=i; p[index].y=j;
}*/
}
}
int step=0;
for(int i=0; i<n; i++){
step+=bfs(i);
}
printf("%d\n", step);
}
int main(){
solve();
}
| a.cc: In function 'int bfs(int)':
a.cc:33:24: error: 'MAX_N\U0000ff1bj' was not declared in this scope
33 | for(int j=0; j<MAX_N;j++){
| ^~~~~~~~
a.cc:33:34: error: expected ';' before ')' token
33 | for(int j=0; j<MAX_N;j++){
| ^
| ;
a.cc:57:1: warning: control reaches end of non-void function [-Wreturn-type]
57 | }
| ^
|
s258542736 | p00481 | C++ | if(temp.x==p[i].x && temp.y==p[i].y)
{
step=use[temp.x][temp.y];
result=result+step;
flag=1;
break;
}
| a.cc:1:25: error: expected unqualified-id before 'if'
1 | if(temp.x==p[i].x && temp.y==p[i].y)
| ^~
|
s716079935 | p00481 | C++ | #include<cstdio>
#include<iostream>
#include<queue>
using namespace std;
#define INF 1000
int H, W, N;
char map[1001][1001];
int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };
int d[1001][1001];
int sx, sy;
int gx, gy;
typedef pair<int, int> P;
int sum = 0;
void bfs()
{
queue<P> que;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
d[i][j] = INF;
que.push(P(sx, sy));
d[sx][sy] = 0;
while (que.size())
{
P p = que.front();
que.pop();
if (p.first == gx&&p.second == gy)break;
for (int i = 0; i < 4; i++)
{
int nx = p.first + dx[i], ny = p.second + dy[i];
if (0 <= nx&&nx < H && 0 <= ny&&ny < W&&map[nx][ny] != 'X'&&d[nx][ny] == INF)
{
que.push(P(nx, ny));
d[nx][ny] = d[p.first][p.second] + 1;
}
}
}
sum+=d[gx][gy];
}
int main()
{
scanf("%d%d%d", &H, &W, &N);
while (getchar() != '\n')continue;
for (int i = 0; i < H; i++){
gets(map[i]);
}
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
{
if (map[i][j] == 'S')
{
sx = i;
sy = j;
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < H; j++)
{
for (int k = 0; k < W; k++)
{
if (map[j][k] == '1' + i)
{
gx = j; gy = k;
bfs();
sx = j; sy = k;
}
}
}
}
printf("%d\n", sum);
}
| a.cc: In function 'int main()':
a.cc:46:9: error: 'gets' was not declared in this scope; did you mean 'getw'?
46 | gets(map[i]);
| ^~~~
| getw
|
s158448055 | p00481 | C++ | #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 1000
int H, W, N;
char map[1001][1001];
int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };
int d[1001][1001];
int sx, sy;
int gx, gy;
typedef pair<int, int> P;
int sum = 0;
void bfs()
{
queue<P> que;
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
d[i][j] = INF;
que.push(P(sx, sy));
d[sx][sy] = 0;
while (que.size())
{
P p = que.front();
que.pop();
if (p.first == gx&&p.second == gy)break;
for (int i = 0; i < 4; i++)
{
int nx = p.first + dx[i], ny = p.second + dy[i];
if (0 <= nx&&nx < H && 0 <= ny&&ny < W&&map[nx][ny] != 'X'&&d[nx][ny] == INF)
{
que.push(P(nx, ny));
d[nx][ny] = d[p.first][p.second] + 1;
}
}
}
sum+=d[gx][gy];
}
int main()
{
scanf("%d%d%d", &H, &W, &N);
while (getchar() != '\n')continue;
for (int i = 0; i < H; i++){
gets(map[i]);
}
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
{
if (map[i][j] == 'S')
{
sx = i;
sy = j;
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < H; j++)
{
for (int k = 0; k < W; k++)
{
if (map[j][k] == '1' + i)
{
gx = j; gy = k;
bfs();
sx = j; sy = k;
}
}
}
}
printf("%d\n", sum);
}
| a.cc: In function 'int main()':
a.cc:50:9: error: 'gets' was not declared in this scope; did you mean 'getw'?
50 | gets(map[i]);
| ^~~~
| getw
|
s386409786 | p00481 | C++ | #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <random>
using namespace std;
//呪文
#define DUMPOUT cerr
#define dump(...) DUMPOUT<<" ";DUMPOUT<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;DUMPOUT<<" ";dump_func(__VA_ARGS__)
typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<string, string> pss;
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { ostr << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const stack<_Ty>& s) { if (s.empty()) { ostr << "{ }"; return ostr; } stack<_Ty> t(s); ostr << "{" << t.top(); t.pop(); while (!t.empty()) { ostr << ", " << t.top(); t.pop(); } ostr << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const list<_Ty>& l) { if (l.empty()) { ostr << "{ }"; return ostr; } ostr << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { ostr << ", " << *itr; } ostr << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { istr >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) istr >> v[i]; return istr; }
namespace aux { // print tuple
template<typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream& os, const Ty& v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } };
template<typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream& os, const Ty& value) { os << get<N>(value); } };
}
template<typename... Tys> ostream& operator<<(ostream& os, const tuple<Tys...>& t) { os << "{"; aux::tp<tuple<Tys...>, 0, sizeof...(Tys)-1>::print(os, t); os << "}"; return os; }
template<typename A, size_t N, typename T> inline void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); }
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); }
#define PI 3.14159265358979323846
#define EPS 1e-11
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define fake false
const int di[] = { 0, -1, 0, 1 };
const int dj[] = { 1, 0, -1, 0 };
void print_board(const vector<vector<int>>& v) {
REP(i, v.size()){
REP(j, v[i].size()) {
if (v[i][j] == -1) printf(" .");
else if (v[i][j] == -2) printf(" #");
else printf("%2d", v[i][j]);
}
printf("\n");
}
}
int main()
{
//clock_t start, end;
//start = clock();
cin.tie(0);
ios::sync_with_stdio(false);
int H, W, N;
cin >> H >> W >> N;
vector<string> S(H);
cin >> S;
vector<pii> points(N + 1);
const int space = -1;
const int block = -2;
vector<vector<int>> board(H, vector<int>(W, space));
REP(i, H) REP(j, W) {
if (S[i][j] == 'S') points[0] = pii(i, j);
else if ('0' <= S[i][j] && S[i][j] <= '9') points[S[i][j] - '0'] = pii(i, j);
else if (S[i][j] == 'X') board[i][j] = block;
}
int ans = 0;
REP(k, N) {
pii from = points[k], to = points[k + 1];
vector<vector<int>> btmp(board);
queue<pii> qu;
qu.push(from);
btmp[from.first][from.second] = 0;
while (!qu.empty()) {
pii p = qu.front(); qu.pop();
int i = p.first, j = p.second;
int step = btmp[i][j];
if (p == to) {
ans += step;
break;
}
REP(d, 4) {
int ni = i + di[d], nj = j + dj[d];
if (ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
if (btmp[ni][nj] == block) continue;
if (btmp[ni][nj] >= 0) continue;
btmp[ni][nj] = step + 1;
qu.push(pii(ni, nj));
}
}
}
cout << ans << endl;
//end = clock();
//printf("%d msec.\n", end - start);
return 0;
}
v
| a.cc:119:1: error: '\U0000ff56' does not name a type
119 | v
| ^~
|
s837822148 | p00481 | C++ | #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
struct node
{
int x,y;
int d;
node(int a,int b,int c)
:x(a),y(b),d(c){}
};
int m,n,p;
char w[1005][1005];
int res;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
void bfs(int x,int y)
{
queue<node> que;
que.push(node(x,y,0));
for(int i=1;i<=p;i++)
{
while(!que.empty())
{
node q=que.front();
que.pop();
if(w[q.x][q.y]-'0'==i)
{
res+=q.d;
while(!que.empty())
que.pop();
que.push(node(q.x,q.y,0));
break;
}
for(int j=0;j<4;j++)
{
int fx=q.x+dx[j],fy=q.y+dy[j];
if(fx>=0&fx<m&&fy>=0&&fy<n)
{
if(w[fx][fy]!='X')
{
que.push(node(fx,fy,q.d+1));
}
}
}
}
}
}
int main()
{
scanf("%d%d%d",&m,&n,&p)
res=0;
for(int i=0;i<m;i++)
scanf("%s",w[i]);
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(w[i][j]=='S')
bfs(i,j);
}
}
printf("%d\n",res);
return 0;
}
| a.cc: In function 'int main()':
a.cc:52:33: error: expected ';' before 'res'
52 | scanf("%d%d%d",&m,&n,&p)
| ^
| ;
53 |
54 | res=0;
| ~~~
|
s130327193 | p00481 | C++ | #include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
int W, H, N;
typedef pair<int, int> P;
queue<P> que;
char maze[1003][1003];
int timer[1003][1003];
int pos_x, pos_y;
int sh_x[4] = {0, 0, -1, 1};
int sh_y[4] = {1, -1, 0, 0};
int res = 0;
int strength = 1;
void solve() {
que.push(P(pos_x, pos_y));
while(que.size()) {
P pos = que.front(); que.pop();
if (maze[pos.second][pos.first] - '0' == strength) {
//printf("[%d] [%d]\n", pos.second, pos.first);
while(que.size()) que.pop();
strength++;
if (strength == N+1) {
res = timer[pos.second][pos.first];
break;
}
for (int i=0;i<H;i++) {
for (int j=0;j<W;j++) {
if (maze[i][j] == '#') maze[i][j] = '.';
}
}
maze[pos.second][pos.first] = '#';
que.push(pos);
continue;
}
for (int i=0;i<4;i++) {
int new_x = pos.first + sh_x[i];
int new_y = pos.second + sh_y[i];
if (new_x >= 0 && new_x < W && new_y >=0 && new_y < H && maze[new_y][new_x] != '#' && maze[new_y][new_x] != 'X') {
//printf("Go to [%d] [%d]\n", new_y, new_x);
que.push(P(new_x, new_y));
if (maze[new_y][new_x] == '.') {
maze[new_y][new_x] = '#';
}
timer[new_y][new_x] = timer[pos.second][pos.first] + 1;
}
}
}
}
int main() {
while (1)
{
scanf("%d %d %d", &H, &W, &N);
getchar();
if (!W && !H) {
break;
}
for (int i = 0; i < H; i++)
{
fgets(maze[i], 1002, stdin);
maze[i][W] = '#';
}
for (int i=0;i<H;i++) {
for (int j=0;j<W;j++) {
if (maze[i][j] == 'S') {
pos_x = j;
pos_y = i;
}
if (i==H-1) {
maze[H][j] = '#';
}
}
}
solve();
printf("%d\n", res);
memset(timer, 0, sizeof(timer[0][0]) * H * W);
strength = 1;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:86:5: error: 'memset' was not declared in this scope
86 | memset(timer, 0, sizeof(timer[0][0]) * H * W);
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 |
|
s052580023 | p00481 | C++ | #include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
int W, H, N;
typedef pair<int, int> P;
queue<P> que;
char maze[1003][1003];
int timer[1003][1003];
int pos_x, pos_y;
int sh_x[4] = {0, 0, -1, 1};
int sh_y[4] = {1, -1, 0, 0};
int res = 0;
int strength = 1;
void solve() {
que.push(P(pos_x, pos_y));
while(que.size()) {
P pos = que.front(); que.pop();
if (maze[pos.second][pos.first] - '0' == strength) {
//printf("[%d] [%d]\n", pos.second, pos.first);
while(que.size()) que.pop();
strength++;
if (strength == N+1) {
res = timer[pos.second][pos.first];
break;
}
for (int i=0;i<H;i++) {
for (int j=0;j<W;j++) {
if (maze[i][j] == '#') maze[i][j] = '.';
}
}
maze[pos.second][pos.first] = '#';
que.push(pos);
continue;
}
for (int i=0;i<4;i++) {
int new_x = pos.first + sh_x[i];
int new_y = pos.second + sh_y[i];
if (new_x >= 0 && new_x < W && new_y >=0 && new_y < H && maze[new_y][new_x] != '#' && maze[new_y][new_x] != 'X') {
//printf("Go to [%d] [%d]\n", new_y, new_x);
que.push(P(new_x, new_y));
if (maze[new_y][new_x] == '.') {
maze[new_y][new_x] = '#';
}
timer[new_y][new_x] = timer[pos.second][pos.first] + 1;
}
}
}
}
int main() {
while (1)
{
scanf("%d %d %d", &H, &W, &N);
getchar();
if (!W && !H) {
break;
}
for (int i = 0; i < H; i++)
{
fgets(maze[i], 1002, stdin);
maze[i][W] = '#';
}
for (int i=0;i<H;i++) {
for (int j=0;j<W;j++) {
if (maze[i][j] == 'S') {
pos_x = j;
pos_y = i;
}
if (i==H-1) {
maze[H][j] = '#';
}
}
}
solve();
printf("%d\n", res);
memset(timer, 0, sizeof(timer[0][0]) * H * W);
strength = 1;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:86:5: error: 'memset' was not declared in this scope
86 | memset(timer, 0, sizeof(timer[0][0]) * H * W);
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 |
|
s369428969 | p00481 | C++ | #include <cstdio>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
int W, H, N;
typedef pair<int, int> P;
queue<P> que;
char maze[1003][1003];
int timer[1003][1003];
int pos_x, pos_y;
int sh_x[4] = {0, 0, -1, 1};
int sh_y[4] = {1, -1, 0, 0};
int res = 0;
int strength = 1;
void solve() {
que.push(P(pos_x, pos_y));
while(que.size()) {
P pos = que.front(); que.pop();
if (maze[pos.second][pos.first] - '0' == strength) {
//printf("[%d] [%d]\n", pos.second, pos.first);
while(que.size()) que.pop();
strength++;
if (strength == N+1) {
res = timer[pos.second][pos.first];
break;
}
for (int i=0;i<H;i++) {
for (int j=0;j<W;j++) {
if (maze[i][j] == '#') maze[i][j] = '.';
}
}
maze[pos.second][pos.first] = '#';
que.push(pos);
continue;
}
for (int i=0;i<4;i++) {
int new_x = pos.first + sh_x[i];
int new_y = pos.second + sh_y[i];
if (new_x >= 0 && new_x < W && new_y >=0 && new_y < H && maze[new_y][new_x] != '#' && maze[new_y][new_x] != 'X') {
//printf("Go to [%d] [%d]\n", new_y, new_x);
que.push(P(new_x, new_y));
if (maze[new_y][new_x] == '.') {
maze[new_y][new_x] = '#';
}
timer[new_y][new_x] = timer[pos.second][pos.first] + 1;
}
}
}
}
int main() {
scanf("%d %d %d", &H, &W, &N);
getchar();
if (!W && !H) {
break;
}
for (int i = 0; i < H; i++)
{
fgets(maze[i], 1002, stdin);
maze[i][W] = '#';
}
for (int i=0;i<H;i++) {
for (int j=0;j<W;j++) {
if (maze[i][j] == 'S') {
pos_x = j;
pos_y = i;
}
if (i==H-1) {
maze[H][j] = '#';
}
}
}
solve();
printf("%d\n", res);
return 0;
}
| a.cc: In function 'int main()':
a.cc:62:7: error: break statement not within loop or switch
62 | break;
| ^~~~~
|
s552578080 | p00481 | C++ | #include<iostream>
#include<functional>
#include<queue>
#include<cctype>
#define MAXN 1024
using namespace std;
struct state{
int i,j;
int cost;
state(int i, int j, int cost):i(i),j(j),cost(cost){}
};
const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};
const int infty = 1<<28;
int dist[10][10];
bool isinside(int i, int j, int H, int W){
return 0<=i&&i<H&&0<=j&&j<W;
}
int compute_dist(int n, int H, int W, char M[MAXN][MAXN]){
int si,sj;
queue< state > q;
bool vis[H][W];
dist[n][n]=0;
for(int i = 0; i < H; ++i){
for(int j = 0; j < W; ++j){
vis[i][j]=false;
if(M[i][j]-'0' == n){
si = i;
sj = j;
}
}
}
q.push( state(si,sj,0) );
while(!q.empty()){
state nst=q.front();q.pop();
for(int k = 0; k < 4; ++k){
int ni = nst.i + di[k];
int nj = nst.j + dj[k];
if( isinside(ni,nj,H,W) && !vis[ni][nj] && M[ni][nj] !='X' ){
if( isdigit(M[ni][nj]) ){
dist[n][M[ni][nj]-'0'] = nst.cost+1;
}
vis[ni][nj]=true;
q.push( state(ni,nj,nst.cost+1) );
}
}
}
}
int solve(int H, int W, int N, char M[MAXN][MAXN])
{
int vis[N];
for(int i = 0; i <= N; ++i){
compute_dist(i,H,W,M);
if(i>0)vis[i-1]=i;
}
int min_cost = infty;
do{
int now=0;
int now_power = 1;
int cost=0;
for(int i = 0; i < N; ++i){
if( now_power < vis[i] ){
cost = infty;
break;
}else{
now_power += 1;
//cout << now << ' ' << vis[i] << ' ' << dist[now][vis[i]] << endl;
cost += dist[now][vis[i]];
now = vis[i];
}
}
min_cost = min( min_cost, cost );
}while(next_permutation(vis,vis+N));
return min_cost;
}
int main()
{
int H,W,N;
while(cin >> H >> W >> N){
static char M[MAXN][MAXN];
for(int i = 0; i < H; ++i){
for(int j = 0; j < W; ++j){
cin >> M[i][j];
if(M[i][j]=='S')M[i][j]='0';
}
}
cout << solve(H,W,N,M) << endl;
}
return 0;
} | a.cc: In function 'int compute_dist(int, int, int, char (*)[1024])':
a.cc:55:1: warning: no return statement in function returning non-void [-Wreturn-type]
55 | }
| ^
a.cc: In function 'int solve(int, int, int, char (*)[1024])':
a.cc:81:10: error: 'next_permutation' was not declared in this scope
81 | }while(next_permutation(vis,vis+N));
| ^~~~~~~~~~~~~~~~
|
s711990017 | p00481 | C++ | #include<queue>
#include<cstdio>
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> pii;
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int h,w;
char grid[1000][1000];
int shortestDistance(int x1,int y1,int x2,int y2){
static bool visited[1000][1000];
rep(i,h)rep(j,w) visited[i][j]=false;
visited[y1][x1]=true;
queue< pair<int,pii> > qu; qu.push(mp(0,mp(x1,y1)));
while(1){
pair<int,pii> a=qu.front(); qu.pop();
int d=a.first,x=a.second.first,y=a.second.second;
if(x==x2 && y==y2) return d;
rep(i,4){
int xx=x+dx[i],yy=y+dy[i];
if(0<=xx && xx<w && 0<=yy && yy<h && grid[yy][xx]!='X' && !visited[yy][xx]){
visited[y][x]=true;
qu.push(mp(d+1,mp(xx,yy)));
}
}
}
}
int main(){
int n; scanf("%d%d%d ",&h,&w,&n);
int cx[10],cy[10];
rep(i,h)rep(j,w){
scanf("%c ",grid[i]+j);
if(grid[i][j]=='S') cx[0]=j,cy[0]=i;
if(isdigit(grid[i][j])) cx[grid[i][j]-'0']=j,cy[grid[i][j]-'0']=i;
}
int cost=0;
rep(i,n) cost+=shortestDistance(cx[i],cy[i],cx[i+1],cy[i+1]);
printf("%d\n",cost);
return 0;
} | a.cc: In function 'int main()':
a.cc:43:20: error: 'isdigit' was not declared in this scope
43 | if(isdigit(grid[i][j])) cx[grid[i][j]-'0']=j,cy[grid[i][j]-'0']=i;
| ^~~~~~~
|
s062851283 | p00481 | C++ | #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef struct{
short x,y;
int cost;
short ch;
}mouse;
mouse Q[10000];
int s,num;
mouse t;
short cx,cy,nx,ny,ch,nch,h,w,n;
int cost;
main(){
scanf("%d%d%d ",&h,&w,&n);
short maxch[h][w];
char ku[h][w];
rep(i,h)gets(ku[i]);
rep(i,h)rep(j,w){
if(ku[i][j]=='S')cx=i,cy=j;
maxch[i][j]=-1;
}
Q[s+num++]=(mouse){cx,cy,0,0};
maxch[cx][cy]=0;
while(true){
t=Q[s++];
num--;
cx=t.x,cy=t.y,cost=t.cost;
ch=t.ch;
rep(i,4){
nx=cx+dx[i],ny=cy+dy[i];
if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
if(ku[nx][ny]=='X')continue;
nch=ch;
if(ku[nx][ny]<='9' && ku[nx][ny]>='1' && ku[nx][ny]-'0'==t.ch+1){
nch=ch+1;
}
if(maxch[nx][ny]>=nch)continue;
if(nch==n){
printf("%d\n",cost+1);
return 0;
}
maxch[nx][ny]=nch;
Q[s+num++]=(mouse){nx,ny,cost+1,nch};
}
}
} | a.cc:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main(){
| ^~~~
a.cc: In function 'int main()':
a.cc:50:11: error: 'gets' was not declared in this scope; did you mean 'getw'?
50 | rep(i,h)gets(ku[i]);
| ^~~~
| getw
|
s709023760 | p00481 | C++ | #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef struct{
short x,y;
int cost;
short ch;
}mouse;
const int MAX=(1<<14)-1;
mouse Q[MAX+1];
int s,num;
mouse t;
short cx,cy,nx,ny,ch,nch,h,w,n;
int cost;
main(){
scanf("%d%d%d ",&h,&w,&n);
short maxch[h][w];
char ku[h][w];
rep(i,h)read(ku[i],1,w+1,0);
rep(i,h)rep(j,w){
if(ku[i][j]=='S')cx=i,cy=j;
maxch[i][j]=-1;
}
Q[s+num++]=(mouse){cx,cy,0,0};
maxch[cx][cy]=0;
while(true){
t=Q[s++&MAX];
num--;
cx=t.x,cy=t.y,cost=t.cost;
ch=t.ch;
rep(i,4){
nx=cx+dx[i],ny=cy+dy[i];
if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
if(ku[nx][ny]=='X')continue;
nch=ch;
if(ku[nx][ny]<='9' && ku[nx][ny]>='1' && ku[nx][ny]-'0'==t.ch+1){
nch=ch+1;
}
if(maxch[nx][ny]>=nch)continue;
if(nch==n){
printf("%d\n",cost+1);
return 0;
}
maxch[nx][ny]=nch;
Q[s+num++&MAX]=(mouse){nx,ny,cost+1,nch};
}
}
} | a.cc:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main(){
| ^~~~
a.cc: In function 'int main()':
a.cc:51:11: error: 'read' was not declared in this scope; did you mean 'fread'?
51 | rep(i,h)read(ku[i],1,w+1,0);
| ^~~~
| fread
|
s607977237 | p00481 | C++ | #include <iostream>
#include <vector>
#include <queue>
#include <string>
using namespace std;
vector<string> field;
pair<int,int> start;
pair<int,int> factory[10];
int h,w,n;
const int INF = 100000000;
// £Ì×ÚXg
int d[10][10];
// Ú®Ê
const int dy[] = {-1,0,0,1};
const int dx[] = {0,-1,1,0};
// ø«Å^¦çê½ê©çDæTõðs¤
void bfs(int idx){
queue<pair<int,int> > *prv = new queue<pair<int,int> >();
queue<pair<int,int> > *nxt = new queue<pair<int,int> >();
// ÊßÏÝÌêði[
bool passed[1001][1001];
// falseÅú»
for(int i = 0; i < 1001; i++)
fill(passed[i],passed[i]+1001,false);
// ÅÌê
prv->push(factory[idx]);
int dist = 0;
// TõJn
while(prv->size()){
while(prv->size()){
// ¡ñÌê
pair<int,int> place = prv->front();prv->pop();
if(passed[place.first][place.second]){
continue;
}
//ÊßÏÝÉ·é
passed[place.first][place.second] = true;
// £ðXV
if(field[place.first][place.second] == 'S'){
d[idx][0] = dist;
}
else if(field[place.first][place.second] >= '0' && field[place.first][place.second] <= '9'){
d[idx][field[place.first][place.second] - '0'] = dist;
}
// Ú®
for(int i = 0; i < 4; i++){
// Ú®æ
pair<int,int> np = place;
np.first += dy[i];
np.second += dx[i];
if(np.first >= 0 && np.second >= 0 && np.first < h && np.second < w){
// áQ¨ÅÈ¢êAÚ®
if(field[np.first][np.second] != 'X' && !passed[np.first][np.second]){
nxt->push(np);
}
}
}
}
dist++;
// obt@¢ê©¦
swap(prv,nxt);
}
}
int main(){
while(cin >> h >> w >> n){
for(int i = 0; i < h; i++){
string str;
cin >> str;
field.push_back(str);
for(int j = 0; j < str.size(); j++){
// X^[gn_ðL^µÄ¨
if(field[i][j] == 'S'){
factory[0].first = i;
factory[0].second = j;
}
// HêÌêðL¯
else if(field[i][j] >= '1' && field[i][j] <= '9'){
factory[field[i][j]-'0'] = make_pair(i,j);
}
}
}
for(int i = 0; i < 10; i++)
fill(d[i],d[i]+10,INF);
// éX^[gn_ܽÍHê©çÊÌHêÖÌÅZ£ðDæTõÅßé
for(int i = 0; i <= n; i++){
bfs(i);
}
vector<int> s;
for(int i = 1; i <= n; i++)
s.push_back(i);
int minCost = INF;
do{
bool f = false;
int sum = 0;
for(int i = 0; i < s.size(); i++){
if(s[i] <= i + 1){
if(i == 0){
sum += d[0][s[i]];
}
else{
sum += d[s[i-1]][s[i]];
}
}
else{
f = true;
break;
}
}
if(!f){
minCost = min(minCost,sum);
}
}while(next_permutation(s.begin(),s.end()));
cout << minCost << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:130:24: error: 'next_permutation' was not declared in this scope
130 | }while(next_permutation(s.begin(),s.end()));
| ^~~~~~~~~~~~~~~~
|
s007535755 | p00481 | C++ | #include <iostream>
#include <vector>
#include <queue>
#include <string>
using namespace std;
vector<string> field;
pair<int,int> start;
pair<int,int> factory[10];
int h,w,n;
const int INF = 100000000;
// £Ì×ÚXg
int d[10][10];
// Ú®Ê
const int dy[] = {-1,0,0,1};
const int dx[] = {0,-1,1,0};
// ø«Å^¦çê½ê©çDæTõðs¤
void bfs(int idx){
queue<pair<int,int> > *prv = new queue<pair<int,int> >();
queue<pair<int,int> > *nxt = new queue<pair<int,int> >();
// ÊßÏÝÌêði[
bool passed[1001][1001];
// falseÅú»
for(int i = 0; i < 1001; i++)
fill(passed[i],passed[i]+1001,false);
// ÅÌê
prv->push(factory[idx]);
int dist = 0;
// TõJn
while(prv->size()){
while(prv->size()){
// ¡ñÌê
pair<int,int> place = prv->front();prv->pop();
if(passed[place.first][place.second]){
continue;
}
//ÊßÏÝÉ·é
passed[place.first][place.second] = true;
// £ðXV
if(field[place.first][place.second] == 'S'){
d[idx][0] = dist;
}
else if(field[place.first][place.second] >= '0' && field[place.first][place.second] <= '9'){
d[idx][field[place.first][place.second] - '0'] = dist;
}
// Ú®
for(int i = 0; i < 4; i++){
// Ú®æ
pair<int,int> np = place;
np.first += dy[i];
np.second += dx[i];
if(np.first >= 0 && np.second >= 0 && np.first < h && np.second < w){
// áQ¨ÅÈ¢êAÚ®
if(field[np.first][np.second] != 'X' && !passed[np.first][np.second]){
nxt->push(np);
}
}
}
}
dist++;
// obt@¢ê©¦
swap(prv,nxt);
}
}
int main(){
while(cin >> h >> w >> n){
for(int i = 0; i < h; i++){
string str;
cin >> str;
field.push_back(str);
for(int j = 0; j < str.size(); j++){
// X^[gn_ðL^µÄ¨
if(field[i][j] == 'S'){
factory[0].first = i;
factory[0].second = j;
}
// HêÌêðL¯
else if(field[i][j] >= '1' && field[i][j] <= '9'){
factory[field[i][j]-'0'] = make_pair(i,j);
}
}
}
for(int i = 0; i < 10; i++)
fill(d[i],d[i]+10,INF);
for(int i = 0; i <= n; i++){
bfs(i);
}
vector<int> s;
for(int i = 1; i <= n; i++)
s.push_back(i);
int minCost = INF;
do{
bool f = false;
int sum = 0;
for(int i = 0; i < s.size(); i++){
if(s[i] <= i + 1){
if(i == 0){
sum += d[0][s[i]];
}
else{
sum += d[s[i-1]][s[i]];
}
}
else{
f = true;
break;
}
}
if(!f){
minCost = min(minCost,sum);
}
}while(next_permutation(s.begin(),s.end()));
cout << minCost << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:130:24: error: 'next_permutation' was not declared in this scope
130 | }while(next_permutation(s.begin(),s.end()));
| ^~~~~~~~~~~~~~~~
|
s490435918 | p00481 | C++ | #include<iostream>
#include<cstdio>
#include<queue>
#include<map>
using namespace std;
typedef pair<unsigned short,unsigned short> P;
typedef pair<unsigned char,int> T;
typedef pair<T,P> PP;
#define rep(i,n) for(i=0;i<n;i++)
#define MAX 1000
char F[MAX][MAX];
char Dx[]={1,0,-1,0},Dy[]={0,1,0,-1};
unsigned short h,w,n,x,y,nx,ny;
P dist[10];
int bfs()
{
bool used[9][MAX][MAX]={};
int c,res=0,u=0;
unsigned char t,i;
PP p;
queue<PP> q;
rep(i,9)
q.push(PP(T(i+'1',0),dist[i]));
while(!q.empty()){
p=q.front();
q.pop();
t=p.first.first;
if(u&(1<<(t-'1')))continue;
c=p.first.second;
x=p.second.first;
y=p.second.second;
c++;
rep(i,4){
nx=x+Dx[i]; ny=y+Dy[i];
if(nx<w&&ny<h&&F[ny][nx]!='X'&&!used[t-'1'][ny][nx]){
used[t-'1'][ny][nx]=true;
if(F[ny][nx]==t){
u|=(1<<(t-'1'));
res+=c;
}
else{
q.push(PP(T(t,c),P(nx,ny)));
}
}
}
}
return res;
}
int main(void)
{
unsigned short i,j;
int res;
scanf("%hd%hd%hd",&h,&w,&n);
rep(i,h) rep(j,w){
scanf(" %c",F[i]+j);
if(F[i][j]=='S')
dist[0]=P(j,i);
else if(F[i][j]!='X'&&F[i][j]!='.')
dist[F[i][j]-'0']=P(j,i);
}
res=bfs();
printf("%d\n",res);
return 0; | a.cc: In function 'int main()':
a.cc:63:12: error: expected '}' at end of input
63 | return 0;
| ^
a.cc:50:1: note: to match this '{'
50 | {
| ^
|
s680478146 | p00481 | C++ | import java.util.*;
import java.math.*;
import java.io.*;
import java.util.regex.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.lang.System.*;
public class Main {
Scanner cin;
class State{
int time,x,y;
State(int time,int x,int y){
this.time=time;
this.x=x;
this.y=y;
}
}
void run(){
cin=new Scanner(System.in);
int H=cin.nextInt(),W=cin.nextInt(),N=cin.nextInt();
String[] MAP=new String[H];
int []dx={1,0,-1,0},dy={0,1,0,-1};
int result=0;
for(int i=0;i<H;i++)MAP[i]=cin.next().replaceAll("S","0");
for(int i=0;i<N;i++){
int sx=-1,sy=-1;
Queue<State> que=new LinkedList<State>();
Boolean[][] visited=new Boolean[H][W];
for(int p=0;p<H;p++){
for(int q=0;q<W;q++){
visited[p][q]=false;
if(MAP[p].charAt(q)==i+'0'){
sx=q;sy=p;
}
}
}
que.add(new State(0,sx,sy));
while(!que.isEmpty()){
State now=que.poll();
if(MAP[now.y].charAt(now.x)==i+1+'0'){
result+=now.time;
break;
}
for(int k=0;k<4;k++){
int nx=now.x+dx[k],ny=now.y+dy[k];
if(nx>=0&&nx<W&&ny>=0&&ny<H){
if(visited[ny][nx]==false&&MAP[ny].charAt(nx)!='X'){
visited[ny][nx]=true;
que.add(new State(now.time+1,nx,ny));
}
}
}
}
}
printf("%d\n",result);
}
void printf(String format,Object... args){
System.out.printf(format, args);
}
public static void main(String[] args) {
new Main().run();
}
} | a.cc:1:1: error: 'import' does not name a type
1 | import java.util.*;
| ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
2 | import java.math.*;
| ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
3 | import java.io.*;
| ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
4 | import java.util.regex.*;
| ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
5 | import static java.lang.Math.*;
| ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
6 | import static java.util.Arrays.*;
| ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
7 | import static java.lang.System.*;
| ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:9:1: error: expected unqualified-id before 'public'
9 | public class Main {
| ^~~~~~
|
s889613838 | p00481 | C++ | #include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<queue>
using namespace std;
char f[1001][1001];
int d[1001][1001];
int h , w , n , x , y , ans;
typedef pair<int,int> P;
int dx[] = {1,0,-1,0} , dy[] = {0,-1,0,1};
int bfs(int to){
for( int i = 0 ; i < h ; i++)
for( int j = 0 ; j < w ; j++)
d[i][j] = 0;
queue<P> q;
q.push(make_pair(x,y));
d[y][x]=1;
while(!q.empty()){
P p = q.front();
q.pop();
if(f[p.second][p.first] - '0' == to){
x = p.first;
y = p.second;
break;
}
for(int i = 0 ; i < 4 ; i ++){
int nx = p.first + dx[i], ny = p.second + dy[i];
if(nx >= 0 && nx < w && ny < h && ny >=0 && d[ny][nx] == 0 && f[ny][nx] != 'X'){
d[ny][nx] = d[p.second][p.first] + 1;
q.push(make_pair(nx,ny));
}
}
}
return d[y][x] - 1;
} | /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.