submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
3 values
code
stringlengths
1
522k
compiler_output
stringlengths
43
10.2k
s435498001
p00212
C++
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <numeric> using namespace std; #define NONE -1 int c,n,m,s,d; vector < vector <int> > P; vector < vector <int> > E; vector <int> R; vector <bool> V; int answer; void solve( int t ) { if ( t == d ) { sort( R.rbegin(), R.rend() ); for ( int i = 0; i < min(c,R.size()); i++ ) { R[i] /= 2; } if ( answer == -1 ) answer = accumulate( R.begin(), R.end(), 0 ); else answer = min( answer, accumulate( R.begin(), R.end(), 0 ) ); } else { V[t] = true; for ( vector <int>::iterator it = E[t].begin(); it != E[t].end(); it++ ) { if ( V[*it] == false ) { R.push_back( P[t][*it] ); solve(*it); R.pop_back(); } } V[t] = false; } } int main( void ) { while ( cin >> c >> n >> m >> s >> d && c && n && m && s && d ) { s--; d--; P = vector < vector <int> >(n+1, vector <int>(n+1,NONE)); E = vector < vector <int> >(n+1); for ( int i = 0; i < m; i++ ) { int a, b, f; cin >> a >> b >> f; P[a-1][b-1] = f; P[b-1][a-1] = f; E[a-1].push_back( b-1 ); E[b-1].push_back( a-1 ); } R = vector <int>(); V = vector <bool>(n+1,false); answer = -1; solve( s ); cout << answer << endl; } return 0; }
a.cc: In function 'void solve(int)': a.cc:22:41: error: no matching function for call to 'min(int&, std::vector<int>::size_type)' 22 | for ( int i = 0; i < min(c,R.size()); i++ ) | ~~~^~~~~~~~~~~~ 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:1: /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:22:41: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'std::vector<int>::size_type' {aka 'long unsigned int'}) 22 | for ( int i = 0; i < min(c,R.size()); i++ ) | ~~~^~~~~~~~~~~~ /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:22:41: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 22 | for ( int i = 0; i < min(c,R.size()); i++ ) | ~~~^~~~~~~~~~~~
s545431439
p00212
C++
#include<iostream> #include<vector> #include<algorithm> #include<queue> using namespace std; typedef pair<int,pair<int,int> >P; struct Edge{ int to,cost; Edge(int _to, int _cost):to(_to), cost(_cost){}; }; int minCost[101][11]; vector<Edge> edge[101]; static const int INF = INT_MAX; int c,n,m,s,d; int dijkstra(void){ priority_queue<P, vector<P>, greater<P> >que; que.push(make_pair(0,make_pair(s,c))); for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) minCost[i][j]=INF; while(!que.empty()){ P p = que.top(); que.pop(); if(p.second.first==d)return p.first; for(int i=0;i<edge[p.second.first].size();i++){ Edge e = edge[p.second.first][i]; que.push(make_pair(p.first+e.cost,make_pair(e.to,p.second.second))); } if(p.second.second==0)continue; for(int j=0;j<edge[p.second.first].size();j++){ Edge e = edge[p.second.first][j]; que.push(make_pair(p.first+e.cost/2,make_pair(e.to,p.second.second-1))); } } return -1; } int main(void){ int a,b,f; while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){ for(int i=0;i<=n;i++)edge[i].clear(); for(int i=0;i<m;i++){ cin >> a >> b >> f; edge[a].push_back(Edge(b,f)); edge[b].push_back(Edge(a,f)); } cout << dijkstra() << endl; } return 0; }
a.cc:17:24: error: 'INT_MAX' was not declared in this scope 17 | static const int INF = INT_MAX; | ^~~~~~~ a.cc:5:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 4 | #include<queue> +++ |+#include <climits> 5 |
s931485722
p00212
C++
#include <map> #include <vector> #include <cstdio> using namespace std; int cost[101][11]; int main(){ int c,N,m,s,d,i,j,k,x; for(;scanf("%d%d%d%d%d",&c,&N,&m,&s,&d),N;){ vector<map<int,int> >dist(N+1); memset(cost,99,sizeof(cost)); for(k=0;k<m;k++){ scanf("%d%d%d",&i,&j,&x);dist[i][j]=dist[j][i]=x; } for(i=0;i<=c;i++)cost[s][i]=0; for(;~c;c--){ vector<bool>used(N+1); for(;;){ //dijkstra int m=9999999; for(i=0;i<N;i++)if(!used[i]&&m>cost[i][c])m=cost[i][c]; if(m==9999999)break; for(j=0;j<N;j++)if(m==cost[j][c]){ map<int,int>::iterator it=dist[j].begin(); for(used[j]=1;it!=dist[j].end();it++){ if(cost[it->first][c]>it->second+cost[j][c])cost[it->first][c]=it->second+cost[j][c]; if(c&&cost[it->first][c-1]>it->second/2+cost[j][c])cost[it->first][c-1]=it->second/2+cost[j][c]; } } } } printf("%d\n",cost[d][0]); } }
a.cc: In function 'int main()': a.cc:10:17: error: 'memset' was not declared in this scope 10 | memset(cost,99,sizeof(cost)); | ^~~~~~ a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 3 | #include <cstdio> +++ |+#include <cstring> 4 | using namespace std;
s014312273
p00212
C++
/* * アルゴリズムとしてはチケットの枚数分のネットワークをレイヤ構造で持ち * 各々のレイヤから上位レイヤへはチケットを使った場合に遷移するようにする * 上位レイヤから下位レイヤには遷移することができないようにし, * 最下位レイヤの始点から終点と同じ点を表すすべてのレイヤの点までの最短経路を求める. * * (イメージ) * T`T`T` * |/|/| S=始点, o=点, T`=終点 |=辺 /=レイヤ下位から上位への有効辺 * o o o * |/|/| S->T`までの距離で最短のものを求め出力する * S o o *Layer 0 1 2 * **/ #include <iostream> #include <map> #define rep(i,s,t) for(int i=s;i<t;i++) using namespace std; //c層目のid値を返す関数 int id2cid(int c,int id){ return c*1000+id; } //dijkstraアルゴリズム //特に無加工,距離を持った隣接を表すgraphと各点までの距離を保持するdis,始点ssを入力 //計算結果はdisに保持し,返り値は無し void dijkstra(map<int,map<int,int> > &graph,map<int,int> &dis,int ss){ //未確定点を保持する集合multimap,距離をkey,点idをvalueとする multimap<int, int> min; //注目する点pのid値 int pid; //始点をまず入力する min.insert(make_pair(0,ss)); //未確定点がなくなるまで while(!min.empty()){ //未確定の中で一番距離が小さい要素(mapの先頭)を取得し注目点pを得る pid=(*(min.begin())).second; //点pを未確定点集合から削除する min.erase(min.begin()); //pに隣接する点について for(map<int,int>::iterator it=graph[pid].begin();it!=graph[pid].end();it++){ //隣接点のid値cidとその点までの距離distを取得 int cid=(*it).first; int dist=(*it).second; //隣接点が未確定点集合に含まれない,もしくは暫定の距離より小さい場合 //未確定点集合の隣接点の距離を始点から注目点までの距離+注目点からの距離に更新する if((dis.find(cid)!=dis.end() && dis[cid]>dis[pid]+dist) || dis.find(cid)==dis.end()){ min.insert(make_pair(dis[pid]+dist,cid)); dis[cid]=dis[pid]+dist; } } } } int main(void){ int c,n,m,s,d; while(cin >> c >> n >> m >> s >> d){ if(c==0) break; //グラフ構造用意 //mapを用いて辺i,jのコストcで隣接関係を表現 map<int,map<int,int> > graph; //m路線に対して rep(i,0,m){ int a,b,f; cin >> a >> b >> f; //グラフをc+1個の層構造とする rep(j,0,c+1){ //j層目のグラフでは通常料金の移動コストで辺を張る //id2cid(j,id)でj層目の点idを示すid値に変換する //点は最大でも500点しかないため,1000桁目以上がn層目とする. //ex(0層目の点125は id=125,8層目の点125は8125)となる. graph[id2cid(j,a)][id2cid(j,b)]=f; graph[id2cid(j,b)][id2cid(j,a)]=f; //j層目からj+1層目へは割引料金を用いた移動コストの辺を張る //j層目からj-1層目への辺がないため階層が上がるに連れて下がることはできない //j層目はすなわちj回チケットを利用した枚数に相当する. if(j<c){ graph[id2cid(j,a)][id2cid(j+1,b)]=f/2; graph[id2cid(j,b)][id2cid(j+1,a)]=f/2; } } } //各点の最短距離を保持するmap map<int,int> dis; //通常のダイクストラで始点sからの各点への最短距離を求め,計算結果を変数disに保持する dijkstra(graph,dis,id2cid(0,s)); //求め終わると終点dと同じ点である点すべての中から最小値を求める
a.cc: In function 'int main()': a.cc:97:49: error: expected '}' at end of input 97 | dijkstra(graph,dis,id2cid(0,s)); | ^ a.cc:65:44: note: to match this '{' 65 | while(cin >> c >> n >> m >> s >> d){ | ^ a.cc:97:49: error: expected '}' at end of input 97 | dijkstra(graph,dis,id2cid(0,s)); | ^ a.cc:62:15: note: to match this '{' 62 | int main(void){ | ^
s896830723
p00212
C++
#include <iostream> #include <vector> #include <algorithm> #include <functional> #include <queue> #include <numeric> using namespace std; struct edge{ int to, cost; }; typedef pair<int, int> P; const int INF = INT_MAX / 4; int V; vector<edge> G[100]; int D[100]; int pre[100]; int c, n, m, s, d; void dijkstra(int s) { priority_queue<P, vector<P>, greater<P> > que; fill(D, D + 100, INF); fill(pre, pre + 100, -1); D[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (D[v] < p.first) continue; for (int i = 0; i < G[v].size(); i++) { edge e = G[v][i]; if(D[e.to] > D[v] + e.cost) { D[e.to] = D[v] + e.cost; pre[e.to] = v; que.push(P(D[e.to], e.to)); } } } } int solve() { dijkstra(s - 1); vector<int> vec; for (int t = d - 1; pre[t] != -1 ; t = pre[t]) { for (int i = 0; i < G[t].size(); i++) { if(pre[t] == G[t][i].to) { vec.push_back(G[t][i].cost); break; } } } sort(vec.begin(), vec.end(), greater<int>()); for (int i = 0; i < c && i < vec.size(); i++) { vec[i] = vec[i] / 2; } return accumulate(vec.begin(), vec.end(), 0); } int main() { while (cin >> c >> n >> m >> s >> d && c && n && m && s && d) { for (int i = 0; i < 100; i++) { G[i] = vector<edge>(); } for (int i = 0; i < m; i++) { int a, b, f; cin >> a >> b >> f; edge e; e.to = b - 1; e.cost = f; G[a - 1].push_back(e); e.to = a - 1; e.cost = f; G[b - 1].push_back(e); } cout << solve() << endl; } return 0; }
a.cc:12:17: error: 'INT_MAX' was not declared in this scope 12 | const int INF = INT_MAX / 4; | ^~~~~~~ a.cc:7:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 6 | #include <numeric> +++ |+#include <climits> 7 |
s077140454
p00212
C++
#include <iostream> #include <vector> #include <algorithm> #include <functional> #include <queue> #include <numeric> using namespace std; struct edge{ int to, cost; }; typedef pair<int, int> P; const int INF = INT_MAX / 4; int V; vector<edge> G[100]; int D[100]; int pre[100]; int c, n, m, s, d; void dijkstra(int s) { priority_queue<P, vector<P>, greater<P> > que; fill(D, D + 100, INF); fill(pre, pre + 100, -1); D[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (D[v] < p.first) continue; for (int i = 0; i < G[v].size(); i++) { edge e = G[v][i]; if(D[e.to] > D[v] + e.cost) { D[e.to] = D[v] + e.cost; pre[e.to] = v; que.push(P(D[e.to], e.to)); } } } } int solve() { dijkstra(s - 1); vector<int> vec; for (int t = d - 1; pre[t] != -1 ; t = pre[t]) { for (int i = 0; i < G[t].size(); i++) { if(pre[t] == G[t][i].to) { vec.push_back(G[t][i].cost); break; } } } sort(vec.begin(), vec.end(), greater<int>()); for (int i = 0; i < c && i < vec.size(); i++) { vec[i] = vec[i] / 2; } return accumulate(vec.begin(), vec.end(), 0); } int main() { while (cin >> c >> n >> m >> s >> d && c && n && m && s && d) { for (int i = 0; i < 100; i++) { G[i] = vector<edge>(); } for (int i = 0; i < m; i++) { int a, b, f; cin >> a >> b >> f; edge e; e.to = b - 1; e.cost = f; G[a - 1].push_back(e); e.to = a - 1; e.cost = f; G[b - 1].push_back(e); } cout << solve() << endl; } return 0; }
a.cc:12:17: error: 'INT_MAX' was not declared in this scope 12 | const int INF = INT_MAX / 4; | ^~~~~~~ a.cc:7:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 6 | #include <numeric> +++ |+#include <climits> 7 |
s876475673
p00212
C++
#include <iostream> #include <vector> #include <algorithm> #include <functional> #include <queue> #include <numeric> #include <limits> using namespace std; struct edge{ int to, cost; }; typedef pair<int, int> P; const int INF = INT_MAX / 4; int V; vector<edge> G[100]; int D[100]; int pre[100]; int c, n, m, s, d; void dijkstra(int s) { priority_queue<P, vector<P>, greater<P> > que; fill(D, D + 100, INF); fill(pre, pre + 100, -1); D[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (D[v] < p.first) continue; for (int i = 0; i < G[v].size(); i++) { edge e = G[v][i]; if(D[e.to] > D[v] + e.cost) { D[e.to] = D[v] + e.cost; pre[e.to] = v; que.push(P(D[e.to], e.to)); } } } } int solve() { dijkstra(s - 1); vector<int> vec; for (int t = d - 1; pre[t] != -1 ; t = pre[t]) { for (int i = 0; i < G[t].size(); i++) { if(pre[t] == G[t][i].to) { vec.push_back(G[t][i].cost); break; } } } sort(vec.begin(), vec.end(), greater<int>()); for (int i = 0; i < c && i < vec.size(); i++) { vec[i] = vec[i] / 2; } return accumulate(vec.begin(), vec.end(), 0); } int main() { while (cin >> c >> n >> m >> s >> d && c && n && m && s && d) { for (int i = 0; i < 100; i++) { G[i] = vector<edge>(); } for (int i = 0; i < m; i++) { int a, b, f; cin >> a >> b >> f; edge e; e.to = b - 1; e.cost = f; G[a - 1].push_back(e); e.to = a - 1; e.cost = f; G[b - 1].push_back(e); } cout << solve() << endl; } return 0; }
a.cc:13:17: error: 'INT_MAX' was not declared in this scope 13 | const int INF = INT_MAX / 4; | ^~~~~~~ a.cc:8:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 7 | #include <limits> +++ |+#include <climits> 8 |
s070406467
p00213
Java
import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; import scala.languageFeature.postfixOps; import sun.tools.jar.resources.jar; import lombok.Data; public class Main { public static void main(String[] args) throws IOException { new Main().run(); } private void run() throws IOException { Scanner scanner = new Scanner(System.in); while (true) { w = scanner.nextInt(); h = scanner.nextInt(); n = scanner.nextInt(); if ((w | h | n) == 0) break; size = new int[n + 1]; pos = new int[n + 1][2]; for (int i = 0; i < n; i++) { int b = scanner.nextInt(); int k = scanner.nextInt(); size[b] = k; } m = new int[h][w]; for (int[] a : m) Arrays.fill(a, -1); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int x = scanner.nextInt(); m[i][j] = x; if (x > 0) { pos[x][0] = i; pos[x][1] = j; } } } assign = new int[n + 1][4]; c = 0; ans = new int[h][w]; f(1); if (c == 1) { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j > 0) System.out.print(" "); System.out.print(ans[i][j]); } System.out.println(); } } else { System.out.println("NA"); } } } private void f(int k) { if (k == n + 1) { c++; if (c == 2) return; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int a = m[i][j]; ans[i][j] = a >= 100 ? a / 100 : a; } } return; } int s = size[k]; for (int x = 1; x <= s; x++) { if (s % x != 0) continue; for (int lj = pos[k][1] + 1 - x; lj <= pos[k][1]; lj++) { if (lj < 0 || lj > w) continue; loop: for (int li = pos[k][0] + 1 - s / x; li <= pos[k][0]; li++) { if (li < 0 || li > h) continue; int rj = lj + x; int ri = li + s / x; if (rj > w) continue; if (ri > h) continue; for (int i = li; i < ri; i++) { for (int j = lj; j < rj; j++) { if (m[i][j] != 0 && m[i][j] != k) continue loop; } } for (int i = li; i < ri; i++) { for (int j = lj; j < rj; j++) { if (m[i][j] != k) m[i][j] = k * 100; } } f(k + 1); if (c == 2) return; for (int i = li; i < ri; i++) { for (int j = lj; j < rj; j++) { if (m[i][j] != k) m[i][j] = 0; } } } } } } int[][] m; int[] size; int[][] pos; int[][] assign; int w, h, n, c; int[][] ans; }
Main.java:9: error: package scala.languageFeature does not exist import scala.languageFeature.postfixOps; ^ Main.java:10: error: package sun.tools.jar.resources is not visible import sun.tools.jar.resources.jar; ^ (package sun.tools.jar.resources is declared in module jdk.jartool, which does not export it) Main.java:11: error: package lombok does not exist import lombok.Data; ^ 3 errors
s518085112
p00213
Java
import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; import scala.languageFeature.postfixOps; import sun.tools.jar.resources.jar; import lombok.Data; public class Main { public static void main(String[] args) throws IOException { new Main().run(); } private void run() throws IOException { Scanner scanner = new Scanner(System.in); while (true) { w = scanner.nextInt(); h = scanner.nextInt(); n = scanner.nextInt(); if ((w | h | n) == 0) break; size = new int[n + 1]; pos = new int[n + 1][2]; for (int i = 0; i < n; i++) { int b = scanner.nextInt(); int k = scanner.nextInt(); size[b] = k; } m = new int[h][w]; for (int[] a : m) Arrays.fill(a, -1); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int x = scanner.nextInt(); m[i][j] = x; if (x > 0) { pos[x][0] = i; pos[x][1] = j; } } } assign = new int[n + 1][4]; c = 0; ans = new int[h][w]; f(1); if (c == 1) { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j > 0) System.out.print(" "); System.out.print(ans[i][j]); } System.out.println(); } } else { System.out.println("NA"); } } } private void f(int k) { if (k == n + 1) { c++; if (c == 2) return; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int a = m[i][j]; ans[i][j] = a >= 100 ? a / 100 : a; } } return; } int s = size[k]; for (int x = 1; x <= s; x++) { if (s % x != 0) continue; for (int lj = pos[k][1] + 1 - x; lj <= pos[k][1]; lj++) { if (lj < 0 || lj > w) continue; loop: for (int li = pos[k][0] + 1 - s / x; li <= pos[k][0]; li++) { if (li < 0 || li > h) continue; int rj = lj + x; int ri = li + s / x; if (rj > w) continue; if (ri > h) continue; for (int i = li; i < ri; i++) { for (int j = lj; j < rj; j++) { if (m[i][j] != 0 && m[i][j] != k) continue loop; } } for (int i = li; i < ri; i++) { for (int j = lj; j < rj; j++) { if (m[i][j] != k) m[i][j] = k * 100; } } f(k + 1); if (c == 2) return; for (int i = li; i < ri; i++) { for (int j = lj; j < rj; j++) { if (m[i][j] != k) m[i][j] = 0; } } } } } } int[][] m; int[] size; int[][] pos; int[][] assign; int w, h, n, c; int[][] ans; }
Main.java:9: error: package scala.languageFeature does not exist import scala.languageFeature.postfixOps; ^ Main.java:10: error: package sun.tools.jar.resources is not visible import sun.tools.jar.resources.jar; ^ (package sun.tools.jar.resources is declared in module jdk.jartool, which does not export it) Main.java:11: error: package lombok does not exist import lombok.Data; ^ 3 errors
s423564856
p00213
Java
import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; import scala.languageFeature.postfixOps; import sun.tools.jar.resources.jar; import lombok.Data; public class Main { public static void main(String[] args) throws IOException { new Main().run(); } private void run() throws IOException { Scanner scanner = new Scanner(System.in); while (true) { w = scanner.nextInt(); h = scanner.nextInt(); n = scanner.nextInt(); if ((w | h | n) == 0) break; size = new int[n + 1]; pos = new int[n + 1][2]; for (int i = 0; i < n; i++) { int b = scanner.nextInt(); int k = scanner.nextInt(); size[b] = k; } m = new int[h][w]; for (int[] a : m) Arrays.fill(a, -1); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int x = scanner.nextInt(); m[i][j] = x; if (x > 0) { pos[x][0] = i; pos[x][1] = j; } } } assign = new int[n + 1][4]; c = 0; ans = new int[h][w]; f(1); if (c == 1) { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j > 0) System.out.print(" "); System.out.print(ans[i][j]); } System.out.println(); } } else { System.out.println("NA"); } } } private void f(int k) { if (k == n + 1) { c++; if (c == 2) return; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int a = m[i][j]; ans[i][j] = a >= 100 ? a / 100 : a; } } return; } int s = size[k]; for (int x = 1; x <= s; x++) { if (s % x != 0) continue; for (int lj = pos[k][1] + 1 - x; lj <= pos[k][1]; lj++) { if (lj < 0 || lj > w) continue; loop: for (int li = pos[k][0] + 1 - s / x; li <= pos[k][0]; li++) { if (li < 0 || li > h) continue; int rj = lj + x; int ri = li + s / x; if (rj > w) continue; if (ri > h) continue; for (int i = li; i < ri; i++) { for (int j = lj; j < rj; j++) { if (m[i][j] != 0 && m[i][j] != k) continue loop; } } for (int i = li; i < ri; i++) { for (int j = lj; j < rj; j++) { if (m[i][j] != k) m[i][j] = k * 100; } } f(k + 1); if (c == 2) return; for (int i = li; i < ri; i++) { for (int j = lj; j < rj; j++) { if (m[i][j] != k) m[i][j] = 0; } } } } } } int[][] m; int[] size; int[][] pos; int[][] assign; int w, h, n, c; int[][] ans; }
Main.java:9: error: package scala.languageFeature does not exist import scala.languageFeature.postfixOps; ^ Main.java:10: error: package sun.tools.jar.resources is not visible import sun.tools.jar.resources.jar; ^ (package sun.tools.jar.resources is declared in module jdk.jartool, which does not export it) Main.java:11: error: package lombok does not exist import lombok.Data; ^ 3 errors
s508540699
p00213
C
X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);}
main.c:1:1: warning: data definition has no type or storage class 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);} | ^ main.c:1:1: error: type defaults to 'int' in declaration of 'X' [-Wimplicit-int] main.c:1:3: error: type defaults to 'int' in declaration of 'Y' [-Wimplicit-int] 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);} | ^ main.c:1:5: error: type defaults to 'int' in declaration of 'n' [-Wimplicit-int] 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);} | ^ main.c:1:7: warning: data definition has no type or storage class 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);} | ^ main.c:1:7: error: type defaults to 'int' in declaration of 'k' [-Wimplicit-int] main.c:1:13: warning: data definition has no type or storage class 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);} | ^ main.c:1:13: error: type defaults to 'int' in declaration of 's' [-Wimplicit-int] main.c:1:23: warning: data definition has no type or storage class 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);} | ^~ main.c:1:23: error: type defaults to 'int' in declaration of 'sd' [-Wimplicit-int] main.c:1:34: warning: data definition has no type or storage class 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);} | ^~ main.c:1:34: error: type defaults to 'int' in declaration of 'dd' [-Wimplicit-int] main.c:1:37: warning: data definition has no type or storage class 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);} | ^~ main.c:1:37: error: type defaults to 'int' in declaration of 'sx' [-Wimplicit-int] main.c:1:44: error: type defaults to 'int' in declaration of 'sy' [-Wimplicit-int] 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&&bx<=sx[b]&&by<=sy[b])for(w=1;h=k[b]/w,w<=h;w++)if(w*h==k[b]){SB(bx,by,w,h,b);w<h&&SB(bx,by,h,w,b);}}main(i,x,y){for(;scanf("%d%d%d",&X,&Y,&n),X;){memset(bf,dd=bn=0,sizeof(bf));for(i=n;i--;k[x]=y)scanf("%d%d",&x,&y);for(y=0;y<Y;y++)for(x=0;x<X;x++){s[x][y]=0;scanf("%d",&i);if(i){sx[i]=x;sy[i]=y;}}SP(0,0);if(dd)for(y=0;y<Y;y++)for(x=0;x<X;x++)printf("%d%c",sd[x][y],x<X-1?32:10);elseputs("NA");}exit(0);} | ^~ main.c:1:51: warning: data definition has no type or storage class 1 | X,Y,n;k[16];s[10][10];sd[10][10];dd;sx[16],sy[16];bf[16];bn;E(bx,by,w,h){int y;for(;w--;)for(y=h;y--;)if(s[bx+w][by+y])return 0;return 1;}F(bx,by,w,h,b){int y;for(;w--;)for(y=h;y--;)s[bx+w][by+y]=b;}SB(bx,by,w,h,b){if(bx+w<=X&&by+h<=Y&&bx+w>sx[b]&&by+h>sy[b]&&E(bx,by,w,h)){F(bx,by,w,h,b);bf[b]=1;++bn==n?dd++&&main(puts("NA")),memcpy(sd,s,sizeof(sd)):SP(bx,by+1);bn--;bf[b]=0;F(bx,by,w,h,0);}}SP(bx,by){int b,w,h;if(by==Y){by-=Y;if(++bx==X)return;}if(s[bx][by])SP(bx,by+1);elsefor(b=1;b<=n;b++)if(!bf[b]&
s045440586
p00213
C++
#include<cstdio> #include<vector> #define mp make_pair #define pb push_back using namespace std; typedef pair<int,int> pii; typedef vector<pii> vpii; vector<vpii> rect; int w,h,n,land[50][50],test[50][50],ans[50][50]; bool search(int i0,int j0){ //printf("i0=%d, j0=%d\n",i0,j0); //for(int a=0;a<h;a++){for(int b=0;b<w;b++)printf("%d ",test[a][b]);puts("");}puts(""); for(int i=i0;i<h;i++){ for(int j=(i==i0?j0:0);j<w;j++){ if(i<0 || h<=i || j<0 || w<=j) exit(0); int id=land[i][j]; if(id==0) continue; if(id<0 || n<id) while(1)puts("@@@@@@"); // try to put a rectangle int cnt=0; for(int k=0;k<rect[id].size();k++){ int rh=rect[id][k].first,rw=rect[id][k].second; for(int y=i-rh+1;y<=i;y++){ for(int x=j-rw+1;x<=j;x++){ if(!(0<=y && y+rh<=h && 0<=x && x+rw<=w)) continue; bool canput=true; for(int yy=y;yy<y+rh;yy++)for(int xx=x;xx<x+rw;xx++){ if(yy<0 || h<=yy || xx<0 || w<=xx) while(1); if(test[yy][xx]!=0 ||(land[yy][xx]!=0 && land[yy][xx]!=id)) canput=false; } if(!canput) continue; for(int yy=y;yy<y+rh;yy++)for(int xx=x;xx<x+rw;xx++){ if(yy<0 || h<=yy || xx<0 || w<=xx) while(1); test[yy][xx]=id; } cnt+=search(i,j+1); for(int yy=y;yy<y+rh;yy++)for(int xx=x;xx<x+rw;xx++){ if(yy<0 || h<=yy || xx<0 || w<=xx) while(1); test[yy][xx]=0; } if(cnt>=2) return false; } } } return (cnt==1)?true:false; } } bool suc=true; for(int i=0;i<h;i++){for(int j=0;j<w;j++){ if(test[i][j]==0) suc=false; }} if(suc){ for(int i=0;i<h;i++){for(int j=0;j<w;j++) ans[i][j]=test[i][j];} return true; } return false; } int main(){ for(;scanf("%d%d%d",&w,&h,&n),w;){ rect=vector<vpii>(n+1); for(int i=0;i<n;i++){ int id,area; scanf("%d%d",&id,&area); for(int j=1;j<=area;j++){ if(area%j==0) rect[id].pb(mp(j,area/j)); } } for(int i=0;i<h;i++){for(int j=0;j<w;j++) scanf("%d",&land[i][j]);} if(search(0,0)){ for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ printf("%s%d",(j?" ":""),ans[i][j]);} putchar('\n'); } } else puts("NA"); } return 0; }
a.cc: In function 'bool search(int, int)': a.cc:21:33: error: 'exit' was not declared in this scope 21 | if(i<0 || h<=i || j<0 || w<=j) exit(0); | ^~~~ a.cc:3:1: note: 'exit' is defined in header '<cstdlib>'; this is probably fixable by adding '#include <cstdlib>' 2 | #include<vector> +++ |+#include <cstdlib> 3 |
s759455240
p00213
C++
#include <iostream> #include <algorithm> #include <queue> using namespace std; int X, Y, n; struct Memo { int b; int k; }; struct Point { int x; int y; }; struct Node { int idx; int a[10][10]; }; class memo_greater { public: bool operator() (const Memo m1, const Memo m2) { return m1.k > m2.k; } }; Point P[15]; Memo M[15]; int A[10][10]; bool is_able(int a[10][10], int x, int y, int w, int h, int idx) { for(int j=y; j<y+h; j++) { for(int i=x; i<x+w; i++) { if(i<0 || j<0 || i>=X || j>=Y) return false; if(a[j][i]!=0 && a[j][i]!=idx) return false; } } return true; } void set(int a[10][10], int x, int y, int w, int h, int idx) { for(int j=y; j<y+h; j++) { for(int i=x; i<x+w; i++) { a[j][i] = idx; } } } bool is_ans() { for(int y=0; y<Y; y++) { for(int x=0; x<X; x++) { if(A[y][x]==0) { return false; } } } return true; } bool solve() { queue<Node> que; int b, k, i, j, mem_size; Point p; bool is_ok; mem_size = sizeof(int) * 100; sort(&M[0], &M[n-1], memo_greater()); Node nn; nn.idx = 0; memcpy(nn.a, A, mem_size); que.push(nn); is_ok = false; while(!que.empty()) { nn = que.front(); que.pop(); if(nn.idx==n) { if(!is_ok) { memcpy(A, nn.a, mem_size); is_ok = true; } else{ return false; } } b = M[nn.idx].b; k = M[nn.idx].k; p = P[b-1]; for(i=1; i<=k; i++) { if(k%i!=0) continue; j = k / i; for(int dy=0; dy<j; dy++) { for(int dx=0; dx<i; dx++) { if(is_able(nn.a, p.x-dx, p.y-dy, i, j, b)) { Node node; memcpy(node.a, nn.a, mem_size); set(node.a, p.x-dx, p.y-dy, i, j, b); node.idx = nn.idx+1; que.push(node); } } } } } return true; } int main(int argc, char** argv) { while( 1 ) { cin >> X >> Y >> n; if(!(X || Y || n)) break; for(int i=0; i<n; i++) { cin >> M[i].b >> M[i].k; } for(int y=0; y<Y; y++) { for(int x=0; x<X; x++) { cin >> A[y][x]; if(A[y][x] != 0) { P[A[y][x]-1].x = x; P[A[y][x]-1].y = y; } } } if(solve()) { for(int y=0; y<Y; y++) { for(int x=0; x<X; x++) { cout << A[y][x]; if(x!=X-1) cout << " "; } cout << endl; } } else { cout << "NA" << endl; } } return 0; }
a.cc: In function 'bool solve()': a.cc:92:9: error: 'memcpy' was not declared in this scope 92 | memcpy(nn.a, A, mem_size); | ^~~~~~ a.cc:4:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 3 | #include <queue> +++ |+#include <cstring> 4 |
s653557250
p00213
C++
#include <iostream> #include <cstdlib> #include <algorithm> #include <queue> using namespace std; int X, Y, n; struct Memo { int b; int k; }; struct Point { int x; int y; }; struct Node { int idx; int a[10][10]; }; class memo_greater { public: bool operator() (const Memo m1, const Memo m2) { return m1.k > m2.k; } }; Point P[15]; Memo M[15]; int A[10][10]; bool is_able(int a[10][10], int x, int y, int w, int h, int idx) { for(int j=y; j<y+h; j++) { for(int i=x; i<x+w; i++) { if(i<0 || j<0 || i>=X || j>=Y) return false; if(a[j][i]!=0 && a[j][i]!=idx) return false; } } return true; } void set(int a[10][10], int x, int y, int w, int h, int idx) { for(int j=y; j<y+h; j++) { for(int i=x; i<x+w; i++) { a[j][i] = idx; } } } bool is_ans() { for(int y=0; y<Y; y++) { for(int x=0; x<X; x++) { if(A[y][x]==0) { return false; } } } return true; } bool solve() { queue<Node> que; int b, k, i, j, mem_size; Point p; bool is_ok; mem_size = sizeof(int) * 100; sort(&M[0], &M[n-1], memo_greater()); Node nn; nn.idx = 0; memcpy(nn.a, A, mem_size); que.push(nn); is_ok = false; while(!que.empty()) { nn = que.front(); que.pop(); if(nn.idx==n) { if(!is_ok) { memcpy(A, nn.a, mem_size); is_ok = true; } else{ return false; } } b = M[nn.idx].b; k = M[nn.idx].k; p = P[b-1]; for(i=1; i<=k; i++) { if(k%i!=0) continue; j = k / i; for(int dy=0; dy<j; dy++) { for(int dx=0; dx<i; dx++) { if(is_able(nn.a, p.x-dx, p.y-dy, i, j, b)) { Node node; memcpy(node.a, nn.a, mem_size); set(node.a, p.x-dx, p.y-dy, i, j, b); node.idx = nn.idx+1; que.push(node); } } } } } return true; } int main(int argc, char** argv) { while( 1 ) { cin >> X >> Y >> n; if(!(X || Y || n)) break; for(int i=0; i<n; i++) { cin >> M[i].b >> M[i].k; } for(int y=0; y<Y; y++) { for(int x=0; x<X; x++) { cin >> A[y][x]; if(A[y][x] != 0) { P[A[y][x]-1].x = x; P[A[y][x]-1].y = y; } } } if(solve()) { for(int y=0; y<Y; y++) { for(int x=0; x<X; x++) { cout << A[y][x]; if(x!=X-1) cout << " "; } cout << endl; } } else { cout << "NA" << endl; } } return 0; }
a.cc: In function 'bool solve()': a.cc:93:9: error: 'memcpy' was not declared in this scope 93 | memcpy(nn.a, A, mem_size); | ^~~~~~ a.cc:5:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 4 | #include <queue> +++ |+#include <cstring> 5 |
s535141613
p00214
Java
### subroutines def o_prod(p, v0, v1) # (p - v0) x (v1 - v0) (p[0] - v0[0]) * (v1[1] - v0[1]) - (v1[0] - v0[0]) * (p[1] - v0[1]) end def inside?(p, vs) nump = numm = 0 (0..3).map{|i| [vs[i], vs[(i + 1) % 4]]}.each do |v0, v1| op = o_prod(p, v0, v1) if op > 0 nump += 1 elsif op < 0 numm += 1 end return false if nump > 0 && numm > 0 end true end def cross_lines?(u0, u1, v0, v1) ux = u1[0] - u0[0] uy = u1[1] - u0[1] vx = v1[0] - v0[0] vy = v1[1] - v0[1] det = -ux * vy * vx * uy return false if det == 0 vux = v0[0] - u0[0] vuy = v0[1] - u0[1] t = (-vy * vux + vx * vuy).to_f / det s = ( uy * vux + ux * vuy).to_f / det t >= 0.0 && t <= 1.0 && s >= 0.0 && s <= 1.0 end def cross_quads?(q1, q2) for p1 in q1 return true if inside?(p1, q2) end for p2 in q2 return true if inside?(p2, q1) end (0..3).map{|i| [q1[i], q1[(i + 1) % 4]]}.each do |u0, u1| (0..3).map{|i| [q2[i], q2[(i + 1) % 4]]}.each do |v0, v1| return true if cross_lines?(u0, u1, v0, v1) end end false end ### main while true n = gets.strip.to_i break if n == 0 n.times.each do m = gets.strip.to_i quads = [] m.times.each do q = gets.strip.split(' ').map{|s| s.to_i} quads << 0.step(6, 2).map{|i| [q[i], q[i + 1]]} end ids = (0...m).map{|id| id} for i in (0...m) for j in ((i + 1)...m) if cross_quads?(quads[i], quads[j]) i0 = i while ids[i0] != i0 ids[i0] = i0 end ids[i0] = j end end end puts (0...m).select{|i| ids[i] == i}.length end end
Main.java:1: error: illegal character: '#' ### subroutines ^ Main.java:1: error: illegal character: '#' ### subroutines ^ Main.java:1: error: illegal character: '#' ### subroutines ^ Main.java:3: error: illegal character: '#' def o_prod(p, v0, v1) # (p - v0) x (v1 - v0) ^ Main.java:10: error: not a statement (0..3).map{|i| [vs[i], vs[(i + 1) % 4]]}.each do |v0, v1| ^ Main.java:10: error: not a statement (0..3).map{|i| [vs[i], vs[(i + 1) % 4]]}.each do |v0, v1| ^ Main.java:10: error: not a statement (0..3).map{|i| [vs[i], vs[(i + 1) % 4]]}.each do |v0, v1| ^ Main.java:3: error: unnamed classes are a preview feature and are disabled by default. def o_prod(p, v0, v1) # (p - v0) x (v1 - v0) ^ (use --enable-preview to enable unnamed classes) Main.java:3: error: <identifier> expected def o_prod(p, v0, v1) # (p - v0) x (v1 - v0) ^ Main.java:3: error: <identifier> expected def o_prod(p, v0, v1) # (p - v0) x (v1 - v0) ^ Main.java:3: error: ';' expected def o_prod(p, v0, v1) # (p - v0) x (v1 - v0) ^ Main.java:10: error: illegal start of expression (0..3).map{|i| [vs[i], vs[(i + 1) % 4]]}.each do |v0, v1| ^ Main.java:10: error: illegal start of expression (0..3).map{|i| [vs[i], vs[(i + 1) % 4]]}.each do |v0, v1| ^ Main.java:10: error: ';' expected (0..3).map{|i| [vs[i], vs[(i + 1) % 4]]}.each do |v0, v1| ^ Main.java:10: error: ';' expected (0..3).map{|i| [vs[i], vs[(i + 1) % 4]]}.each do |v0, v1| ^ Main.java:10: error: class, interface, enum, or record expected (0..3).map{|i| [vs[i], vs[(i + 1) % 4]]}.each do |v0, v1| ^ Main.java:58: error: illegal character: '#' ### main ^ Main.java:58: error: illegal character: '#' ### main ^ Main.java:58: error: illegal character: '#' ### main ^ Main.java:74: error: illegal '.' ids = (0...m).map{|id| id} ^ Main.java:76: error: illegal '.' for i in (0...m) ^ Main.java:88: error: illegal '.' puts (0...m).select{|i| ids[i] == i}.length ^ 22 errors
s728939543
p00214
Java
import java.util.*; public class Main { static boolean used[]; static Point rec[][]; static double EPS=1e-5; public static void main(String[] args) { Scanner in=new Scanner(System.in); for(;;) { int N=in.nextInt(); if(N==0) return; while(N-->0) { int n=in.nextInt(); rec=new Point[n][4]; used=new boolean[n];// true is used... for(int i=0;i<n;i++) for(int j=0;j<4;j++) rec[i][j]=new Point(in.nextDouble(), in.nextDouble()); int cnt=0; for(int i=0;i<n;i++) { if(!used[i]) { ++cnt; dfs(i); } } System.out.println(cnt); } } } static void dfs(int now) { used[now]=true; for(int i=0;i<used.length;i++) { if(!used[i]) { boolean go=false; //交差判定(境界含む) for(int j=0;j<4;j++) for(int k=0;k<4;k++) { if(Point.lineCross(rec[now][j], rec[now][(j+1)%4],rec[i][k] , rec[i][(k+1)%4])) go=true; } for(int k=0;k<4;k++) { if(Point.ccw(rec[now][0],rec[i][k],rec[now][1])==1&&Point.ccw(rec[now][1],rec[i][k],rec[now][2])==1&& Point.ccw(rec[now][2],rec[i][k],rec[now][3])==1&&Point.ccw(rec[now][3],rec[i][k],rec[now][0])==1 ||Point.ccw(rec[now][0],rec[i][k],rec[now][1])==-1&&Point.ccw(rec[now][1],rec[i][k],rec[now][2])==-1&& Point.ccw(rec[now][2],rec[i][k],rec[now][3])==-1&&Point.ccw(rec[now][3],rec[i][k],rec[now][0])==-1) go=true; } for(int k=0;k<n;k++) for(int j=0;j<4;j++) { if(Point.ccw(rec[k][0],rec[now][j],rec[k][1])==1&&Point.ccw(rec[k][1],rec[now][j],rec[k][2])==1&& Point.ccw(rec[k][2],rec[now][j],rec[k][3])==1&&Point.ccw(rec[k][3],rec[now][j],rec[k][0])==1 ||Point.ccw(rec[k][0],rec[now][j],rec[k][1])==-1&&Point.ccw(rec[k][1],rec[now][j],rec[k][2])==-1&& Point.ccw(rec[k][2],rec[now][j],rec[k][3])==-1&&Point.ccw(rec[k][3],rec[now][j],rec[k][0])==-1) go=true; } if(go) dfs(i); } } } static public void debug(Object... o) { System.err.println(Arrays.deepToString(o)); } } class Point { double x; double y; static double EPS=1e-5; Point(double x,double y) { this.x=x; this.y=y; } //線分p1-p2と線分p3-p4が交差しているかを判定 true->交差(=含みで接する含む) false->交差せず static boolean lineCross(Point p1,Point p2,Point p3,Point p4) { double a=(p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x); double b=(p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x); double c=(p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x); double d=(p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x); return a*b<=EPS && c*d<=EPS; } //counterClockWise p1->p2->p3が反時計周りなら1 時計周りなら-1を返す static double ccw(Point p1,Point p2,Point p3) { Point a=new Point(p2.x-p1.x, p2.y-p1.y); Point b=new Point(p3.x-p1.x, p3.y-p1.y); if(crossProduct(a, b)>=-EPS) return 1;//counter clockwise if(crossProduct(a, b)<=EPS) return -1;//clockwise else return 0; } //外積 static double crossProduct(Point a,Point b) { return a.x*b.y-a.y*b.x; } //3頂点からなる三角形の面積 static double triangleArea(Point p1,Point p2,Point p3) { return Math.abs((p3.y-p1.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p3.x-p1.x))/2; } } //x>=yの優先度で頂点を昇順ソート //Arrays.sort(p,new PointComparator());こんな感じで使う class PointComparator implements Comparator<Point> { public int compare(Point p1,Point p2) { double cmp=p1.x-p2.x; if(cmp==0) cmp=p1.y-p2.y; if(cmp<0) cmp=-1; else cmp=1; return (int) cmp; } }
Main.java:63: error: cannot find symbol for(int k=0;k<n;k++) ^ symbol: variable n location: class Main 1 error
s755218166
p00214
Java
import java.util.*; public class Main { static boolean used[]; static Point rec[][]; static double EPS=1e-5; public static void main(String[] args) { Scanner in=new Scanner(System.in); for(;;) { int N=in.nextInt(); if(N==0) return; while(N-->0) { int n=in.nextInt(); rec=new Point[n][4]; used=new boolean[n];// true is used... for(int i=0;i<n;i++) for(int j=0;j<4;j++) rec[i][j]=new Point(in.nextDouble(), in.nextDouble()); int cnt=0; for(int i=0;i<n;i++) { if(!used[i]) { ++cnt; dfs(i); } } System.out.println(cnt); } } } static void dfs(int now) { used[now]=true; for(int i=0;i<used.length;i++) { if(!used[i]) { boolean go=false; //交差判定(境界含む) for(int j=0;j<4;j++) for(int k=0;k<4;k++) { if(Point.lineCross(rec[now][j], rec[now][(j+1)%4],rec[i][k] , rec[i][(k+1)%4])) go=true; } for(int k=0;k<4;k++) { if(Point.ccw(rec[now][0],rec[i][k],rec[now][1])==1&&Point.ccw(rec[now][1],rec[i][k],rec[now][2])==1&& Point.ccw(rec[now][2],rec[i][k],rec[now][3])==1&&Point.ccw(rec[now][3],rec[i][k],rec[now][0])==1 ||Point.ccw(rec[now][0],rec[i][k],rec[now][1])==-1&&Point.ccw(rec[now][1],rec[i][k],rec[now][2])==-1&& Point.ccw(rec[now][2],rec[i][k],rec[now][3])==-1&&Point.ccw(rec[now][3],rec[i][k],rec[now][0])==-1) go=true; } for(int k=0;k<n;k++) { if(Point.ccw(rec[i][0],rec[now][k],rec[i][1])==1&&Point.ccw(rec[i][1],rec[now][k],rec[i][2])==1&& Point.ccw(rec[i][2],rec[now][k],rec[i][3])==1&&Point.ccw(rec[i][3],rec[now][k],rec[i][0])==1 ||Point.ccw(rec[i][0],rec[now][k],rec[i][1])==-1&&Point.ccw(rec[i][1],rec[now][k],rec[i][2])==-1&& Point.ccw(rec[i][2],rec[now][k],rec[i][3])==-1&&Point.ccw(rec[i][3],rec[now][k],rec[i][0])==-1) go=true; } if(go) dfs(i); } } } static public void debug(Object... o) { System.err.println(Arrays.deepToString(o)); } } class Point { double x; double y; static double EPS=1e-5; Point(double x,double y) { this.x=x; this.y=y; } //線分p1-p2と線分p3-p4が交差しているかを判定 true->交差(=含みで接する含む) false->交差せず static boolean lineCross(Point p1,Point p2,Point p3,Point p4) { double a=(p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x); double b=(p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x); double c=(p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x); double d=(p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x); return a*b<=EPS && c*d<=EPS; } //counterClockWise p1->p2->p3が反時計周りなら1 時計周りなら-1を返す static double ccw(Point p1,Point p2,Point p3) { Point a=new Point(p2.x-p1.x, p2.y-p1.y); Point b=new Point(p3.x-p1.x, p3.y-p1.y); if(crossProduct(a, b)>=-EPS) return 1;//counter clockwise if(crossProduct(a, b)<=EPS) return -1;//clockwise else return 0; } //外積 static double crossProduct(Point a,Point b) { return a.x*b.y-a.y*b.x; } //3頂点からなる三角形の面積 static double triangleArea(Point p1,Point p2,Point p3) { return Math.abs((p3.y-p1.y)*(p2.x-p1.x)-(p2.y-p1.y)*(p3.x-p1.x))/2; } } //x>=yの優先度で頂点を昇順ソート //Arrays.sort(p,new PointComparator());こんな感じで使う class PointComparator implements Comparator<Point> { public int compare(Point p1,Point p2) { double cmp=p1.x-p2.x; if(cmp==0) cmp=p1.y-p2.y; if(cmp<0) cmp=-1; else cmp=1; return (int) cmp; } }
Main.java:63: error: cannot find symbol for(int k=0;k<n;k++) ^ symbol: variable n location: class Main 1 error
s384375613
p00214
C
def z a,b,c,d;(b[0]-a[0])*(d[1]-c[1])-(d[0]-c[0])*(b[1]-a[1])end def xx a,b,c,d;(v=z a,b,c,d)!=0&&z(a,c,a,b)/v==0&&z(a,c,c,d)/v==0;end def x a,b (0..3).any?{|k| (0..3).map{|m|z a[m*2-2,2],a[m*2,2],a[m*2-2,2],b[k*2,2]}.all?{|m|m<=0}|| (0..3).map{|m|z b[m*2-2,2],b[m*2,2],b[m*2-2,2],a[k*2,2]}.all?{|m|m<=0}|| (0..3).any?{|m|xx a[k*2-2,2],a[k*2,2],b[m*2-2,2],b[m*2,2]} }end while(n=gets.to_i)>0 n.times{a=[*0..gets.to_i-1] l=a.map{gets.split.map &:to_i} a.map{|i|(i+1..a[-1]).map{|j|x(l[i],l[j])&&(b=[] i=a[i]while(b<< i;a[i]!=i) j=a[j]while(b<< j;a[j]!=j) b.map{|k|a[k]=[i,j].min})}} a.map!{|i|i=a[i]while a[i]!=i;i} p a.uniq.size}end
main.c:1:1: error: unknown type name 'def' 1 | def z a,b,c,d;(b[0]-a[0])*(d[1]-c[1])-(d[0]-c[0])*(b[1]-a[1])end | ^~~ main.c:1:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'a' 1 | def z a,b,c,d;(b[0]-a[0])*(d[1]-c[1])-(d[0]-c[0])*(b[1]-a[1])end | ^ main.c:1:20: error: expected ')' before '-' token 1 | def z a,b,c,d;(b[0]-a[0])*(d[1]-c[1])-(d[0]-c[0])*(b[1]-a[1])end | ^ | ) main.c:2:18: error: expected ')' before '=' token 2 | def xx a,b,c,d;(v=z a,b,c,d)!=0&&z(a,c,a,b)/v==0&&z(a,c,c,d)/v==0;end | ^ | ) main.c:2:67: error: unknown type name 'end' 2 | def xx a,b,c,d;(v=z a,b,c,d)!=0&&z(a,c,a,b)/v==0&&z(a,c,c,d)/v==0;end | ^~~ main.c:3:5: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'x' 3 | def x a,b | ^ main.c:3:5: error: unknown type name 'x' main.c:4:2: error: too many decimal points in number 4 | (0..3).any?{|k| | ^~~~ main.c:5:2: error: too many decimal points in number 5 | (0..3).map{|m|z a[m*2-2,2],a[m*2,2],a[m*2-2,2],b[k*2,2]}.all?{|m|m<=0}|| | ^~~~ main.c:6:2: error: too many decimal points in number 6 | (0..3).map{|m|z b[m*2-2,2],b[m*2,2],b[m*2-2,2],a[k*2,2]}.all?{|m|m<=0}|| | ^~~~ main.c:7:2: error: too many decimal points in number 7 | (0..3).any?{|m|xx a[k*2-2,2],a[k*2,2],b[m*2-2,2],b[m*2,2]} | ^~~~ main.c:9:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'while' 9 | while(n=gets.to_i)>0 | ^~~~~ main.c:10:13: error: too many decimal points in number 10 | n.times{a=[*0..gets.to_i-1] | ^~~~~~~~~~~~ main.c:12:13: error: too many decimal points in number 12 | a.map{|i|(i+1..a[-1]).map{|j|x(l[i],l[j])&&(b=[] | ^~~~ main.c:17:1: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input 17 | p a.uniq.size}end | ^
s282477688
p00214
C++
#include<bits/stdc++.h> using namespace std; typedef complex < double > P; typedef vector< P > G; vector< G > g; const double EPS = 1e-8; const double INF = 1e12; double cross(const P& a,const P& b){ //?????? return imag(conj(a) * b); } double dot(const P& a,const P& b){ // ?????? return real(conj(a) * b); } struct L: vector < P >{ L(const P& a,const P& b){ push_back(a); push_back(b); } }; int ccw(P a,P b,P c){ b -= a; c -= a; if(cross(b,c) > 0) return 1; if(cross(b,c) < 0) return -1; if(dot(b,c) < 0) return 2; // c--a--b if(norm(b) < norm(c)) return -2; // a--b--c return 0; // a--c--b } bool intersectSS(const L& s,const L& t){ //???????????? ??????:?????? return ccw(s[0],s[1],t[0]) * ccw(s[0],s[1],t[1]) <= 0 && ccw(t[0],t[1],s[0]) * ccw(t[0],t[1],s[1]) <= 0; } #define curr(P,i) P
/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
s954134367
p00214
C++
#include<iostream> #include<vector> #include<queue> using namespace std; struct Point { long double px, py; }; Point Minus(const Point& a, const Point& b) { return Point{ a.px - b.px,a.py - b.py }; } long double norm(const Point& a) { return a.px * a.px + a.py * a.py; } long double abs(const Point& a) { return sqrtl(norm(a)); } long double arg(const Point& a) { return atan2l(a.py, a.px); } long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; } long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; } int ccw(const Point& p0, const Point& p1, const Point& p2) { Point a = Minus(p1, p0), b = Minus(p2, p0); if (crs(a, b) > 1e-10) return 1; if (crs(a, b) < -1e-10) return -1; if (dot(a, b) < -1e-10) return 2; if (norm(a) < norm(b)) return -2; return 0; } bool its(const Point& p1, const Point& p2, const Point& p3, const Point& p4) { return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0); } int contain(vector<Point> v, Point p) { bool in = false; for (int i = 0; i < v.size(); ++i) { Point a = Minus(v[i], p), b = Minus(v[(i + 1) % v.size()], p); if (a.py > b.py) swap(a, b); if (a.py <= 0 && 0 < b.py) if (crs(a, b) < 0) in = !in; if (crs(a, b) == 0 && dot(a, b) <= 0) return 1; } return in ? 2 : 0; } bool connect(vector<Point>p1, vector<Point>p2) { for (int i = 0; i < p1.size(); i++) { for (int j = 0; j < p2.size(); j++) { if (its(p1[i], p1[(i + 1) % p1.size()], p2[j], p2[(j + 1) % p2.size()]) == true)return true; } } for (int i = 0; i < p2.size(); i++) { if (contain(p1, p2[i]) != 0)return true; } for (int i = 0; i < p1.size(); i++) { if (contain(p2, p1[i]) != 0)return true; } return false; } vector<Point>r[200]; int n, t; vector<int>X[200]; bool unused[200]; int main() { while (true) { cin >> t; if (t == 0)break; for (int h = 0; h < t; h++) { for (int i = 0; i < 200; i++) { r[i].clear(); r[i].resize(4); X[i].clear(); unused[i] = false; } cin >> n; int cnt = 0; for (int j = 0; j < n; j++) { cin >> r[cnt][0].px >> r[cnt][0].py >> r[cnt][1].px >> r[cnt][1].py; cin >> r[cnt][2].px >> r[cnt][2].py >> r[cnt][3].px >> r[cnt][3].py; cnt++; } for (int i = 0; i < cnt; i++) { for (int j = i + 1; j < cnt; j++) { if (connect(r[i], r[j]) == true) { X[i].push_back(j); X[j].push_back(i); } } } queue<int>Q; int ans = 0; for (int i = 0; i < cnt; i++) { if (unused[i] == true)continue; Q.push(i); unused[i] = true; ans++; while (!Q.empty()) { int a1 = Q.front(); Q.pop(); for (int j = 0; j < X[a1].size(); j++) { if (unused[X[a1][j]] == false) { unused[X[a1][j]] = true; Q.push(X[a1][j]); } } } } cout << ans << endl; } } return 0; }
a.cc: In function 'long double abs(const Point&)': a.cc:8:42: error: 'sqrtl' was not declared in this scope; did you mean 'strtol'? 8 | long double abs(const Point& a) { return sqrtl(norm(a)); } | ^~~~~ | strtol a.cc: In function 'long double arg(const Point&)': a.cc:9:42: error: 'atan2l' was not declared in this scope 9 | long double arg(const Point& a) { return atan2l(a.py, a.px); } | ^~~~~~
s692119522
p00214
C++
#include <iostream> #include <cmath> #include <set> #include <memory> using namespace std; const int size = 101; const double eps = 1e-9; struct Vector2D { int x; int y; Vector2D(): x(0), y(0) {} Vector2D( int x, int y ): x(x), y(y) {} Vector2D operator -( Vector2D& right ) { return Vector2D( x-right.x, y-right.y ); } bool operator ==( Vector2D& right ) { return x == right.x && y == right.y; } }; typedef Vector2D* PVector2D; // ツ四ツ角ツ形ツデツーツタ int Q[size][8]; int QC; void initQ() { QC = 0; } void inputQ() { for ( int i = 0; i < 8; i++ ) { cin >> Q[QC][i]; } QC++; } // disjoint sets int F[size]; int FC; void initF() { FC = 0; } int get( int ind ) { return F[ind] == -1 ? ind : get( F[ind] ); } bool same( int a, int b ) { int fa = get( a ); int fb = get( b ); return fa == fb; } void merge( int a, int b ) { int fa = get( a ); int fb = get( b ); if ( fa != fb ) { F[fb] = fa; } } // PVector2D getTriangleA( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][0], Q[a][1] ); answer[1] = Vector2D( Q[a][2], Q[a][3] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } PVector2D getTriangleB( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][2], Q[a][3] ); answer[1] = Vector2D( Q[a][4], Q[a][5] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } int cross( Vector2D a, Vector2D b ) { return a.x*b.y - a.y*b.x; } int getM( Vector2D a ) { return abs(a.x) + abs(a.y); } bool collision( PVector2D t, Vector2D p ) { for ( int i = 0; i < 3; i++ ) { int ii = i; int kk = (i+2)%3; int c = cross( t[ii]-t[kk], p-t[kk] ); if ( c == 0 && getM( p-t[kk] ) <= getM( t[ii]-t[kk] ) ) { return true; } } for ( int i = 0; i < 3; i++ ) { int ii = i; int jj = (i+1)%3; int kk = (i+2)%3; int c1 = cross( t[ii]-t[kk], p-t[kk] ); int c2 = cross( t[jj]-t[kk], p-t[kk] ); if ( c1 > 0 && c2 > 0 || c1 < 0 && c2 < 0 ) return false; } return true; } bool collision( int a, int b ) { PVector2D ta = getTriangleA( a ); PVector2D tb = getTriangleB( b ); for ( int i = 0; i < 3; i++ ) { if ( collision( ta, tb[i] ) ) return true; if ( collision( tb, ta[i] ) ) return true; } for ( int i = 0; i < 3; i++ ) { for ( int j = 0; j < 3; j++ ) { if ( ta[i] == tb[j] ) return true; } } return false; } int main() { int n; while ( cin >> n && n ) { for ( int i = 0; i < n; i++ ) { initF(); initQ(); int m; cin >> m; int color; for ( int j = 0; j < m; j++ ) { inputQ(); F[FC++] = -1; } for ( int ii = 0; ii < m; ii++ ) { for ( int jj = 0; jj < m; jj++ ) { if ( same( ii, jj ) ) continue; if ( collision( ii, jj ) ) merge( ii, jj ); } } set <int> S; for ( int j = 0; j < m; j++ ) { S.insert( get(j) ); } cout << S.size() << endl; } } return 0; }
a.cc:25:7: error: reference to 'size' is ambiguous 25 | int Q[size][8]; | ^~~~ 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:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:7:11: note: 'const int size' 7 | const int size = 101; | ^~~~ a.cc: In function 'void inputQ()': a.cc:32:16: error: 'Q' was not declared in this scope 32 | cin >> Q[QC][i]; | ^ a.cc: At global scope: a.cc:38:7: error: reference to 'size' is ambiguous 38 | int F[size]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:7:11: note: 'const int size' 7 | const int size = 101; | ^~~~ a.cc: In function 'int get(int)': a.cc:44:12: error: 'F' was not declared in this scope; did you mean 'FC'? 44 | return F[ind] == -1 ? ind : get( F[ind] ); | ^ | FC a.cc: In function 'void merge(int, int)': a.cc:55:9: error: 'F' was not declared in this scope 55 | F[fb] = fa; | ^ a.cc: In function 'Vector2D* getTriangleA(int)': a.cc:62:27: error: 'Q' was not declared in this scope 62 | answer[0] = Vector2D( Q[a][0], Q[a][1] ); | ^ a.cc: In function 'Vector2D* getTriangleB(int)': a.cc:70:27: error: 'Q' was not declared in this scope 70 | answer[0] = Vector2D( Q[a][2], Q[a][3] ); | ^ a.cc: In function 'int main()': a.cc:134:17: error: 'F' was not declared in this scope 134 | F[FC++] = -1; | ^
s944645615
p00214
C++
#include <iostream> #include <cmath> #include <set> #include <memory> using namespace std; const int size = 101; const double eps = 1e-9; struct Vector2D { int x; int y; Vector2D(): x(0), y(0) {} Vector2D( int x, int y ): x(x), y(y) {} Vector2D operator -( Vector2D& right ) { return Vector2D( x-right.x, y-right.y ); } bool operator ==( Vector2D& right ) { return x == right.x && y == right.y; } }; typedef Vector2D* PVector2D; // ツ四ツ角ツ形ツデツーツタ int Q[size][8]; int QC; void initQ() { QC = 0; } void inputQ() { for ( int i = 0; i < 8; i++ ) { cin >> Q[QC][i]; } QC++; } // disjoint sets int F[size]; int FC; void initF() { FC = 0; } int get( int ind ) { return F[ind] == -1 ? ind : get( F[ind] ); } bool same( int a, int b ) { int fa = get( a ); int fb = get( b ); return fa == fb; } void merge( int a, int b ) { int fa = get( a ); int fb = get( b ); if ( fa != fb ) { F[fb] = fa; } } // PVector2D getTriangleA( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][0], Q[a][1] ); answer[1] = Vector2D( Q[a][2], Q[a][3] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } PVector2D getTriangleB( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][2], Q[a][3] ); answer[1] = Vector2D( Q[a][4], Q[a][5] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } int cross( Vector2D a, Vector2D b ) { return a.x*b.y - a.y*b.x; } int getM( Vector2D a ) { return abs(a.x) + abs(a.y); } bool collision( PVector2D t, Vector2D p ) { for ( int i = 0; i < 3; i++ ) { int ii = i; int kk = (i+2)%3; int c = cross( t[ii]-t[kk], p-t[kk] ); if ( c == 0 && getM( p-t[kk] ) <= getM( t[ii]-t[kk] ) ) { return true; } } for ( int i = 0; i < 3; i++ ) { int ii = i; int jj = (i+1)%3; int kk = (i+2)%3; int c1 = cross( t[ii]-t[kk], p-t[kk] ); int c2 = cross( t[jj]-t[kk], p-t[kk] ); if ( ( c1 > 0 && c2 > 0 ) || ( c1 < 0 && c2 < 0 ) ) return false; } return true; } bool collision( int a, int b ) { PVector2D ta = getTriangleA( a ); PVector2D tb = getTriangleB( b ); for ( int i = 0; i < 3; i++ ) { if ( collision( ta, tb[i] ) ) return true; if ( collision( tb, ta[i] ) ) return true; } for ( int i = 0; i < 3; i++ ) { for ( int j = 0; j < 3; j++ ) { if ( ta[i] == tb[j] ) return true; } } return false; } int main() { int n; while ( cin >> n && n ) { for ( int i = 0; i < n; i++ ) { initF(); initQ(); int m; cin >> m; for ( int j = 0; j < m; j++ ) { inputQ(); F[FC++] = -1; } for ( int ii = 0; ii < m; ii++ ) { for ( int jj = 0; jj < m; jj++ ) { if ( same( ii, jj ) ) continue; if ( collision( ii, jj ) ) merge( ii, jj ); } } set <int> S; for ( int j = 0; j < m; j++ ) { S.insert( get(j) ); } cout << S.size() << endl; } } return 0; }
a.cc:25:7: error: reference to 'size' is ambiguous 25 | int Q[size][8]; | ^~~~ 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:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:7:11: note: 'const int size' 7 | const int size = 101; | ^~~~ a.cc: In function 'void inputQ()': a.cc:32:16: error: 'Q' was not declared in this scope 32 | cin >> Q[QC][i]; | ^ a.cc: At global scope: a.cc:38:7: error: reference to 'size' is ambiguous 38 | int F[size]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:7:11: note: 'const int size' 7 | const int size = 101; | ^~~~ a.cc: In function 'int get(int)': a.cc:44:12: error: 'F' was not declared in this scope; did you mean 'FC'? 44 | return F[ind] == -1 ? ind : get( F[ind] ); | ^ | FC a.cc: In function 'void merge(int, int)': a.cc:55:9: error: 'F' was not declared in this scope 55 | F[fb] = fa; | ^ a.cc: In function 'Vector2D* getTriangleA(int)': a.cc:62:27: error: 'Q' was not declared in this scope 62 | answer[0] = Vector2D( Q[a][0], Q[a][1] ); | ^ a.cc: In function 'Vector2D* getTriangleB(int)': a.cc:70:27: error: 'Q' was not declared in this scope 70 | answer[0] = Vector2D( Q[a][2], Q[a][3] ); | ^ a.cc: In function 'int main()': a.cc:133:17: error: 'F' was not declared in this scope 133 | F[FC++] = -1; | ^
s409877486
p00214
C++
#include <iostream> #include <stdlib> #include <set> #include <memory> using namespace std; const int size = 101; const double eps = 1e-9; struct Vector2D { int x; int y; Vector2D(): x(0), y(0) {} Vector2D( int x, int y ): x(x), y(y) {} Vector2D operator -( Vector2D& right ) { return Vector2D( x-right.x, y-right.y ); } bool operator ==( Vector2D& right ) { return x == right.x && y == right.y; } }; typedef Vector2D* PVector2D; // ツ四ツ角ツ形ツデツーツタ int Q[size][8]; int QC; void initQ() { QC = 0; } void inputQ() { for ( int i = 0; i < 8; i++ ) { cin >> Q[QC][i]; } QC++; } // disjoint sets int F[size]; int FC; void initF() { FC = 0; } int get( int ind ) { return F[ind] == -1 ? ind : get( F[ind] ); } bool same( int a, int b ) { int fa = get( a ); int fb = get( b ); return fa == fb; } void merge( int a, int b ) { int fa = get( a ); int fb = get( b ); if ( fa != fb ) { F[fb] = fa; } } // PVector2D getTriangleA( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][0], Q[a][1] ); answer[1] = Vector2D( Q[a][2], Q[a][3] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } PVector2D getTriangleB( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][2], Q[a][3] ); answer[1] = Vector2D( Q[a][4], Q[a][5] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } int cross( Vector2D a, Vector2D b ) { return a.x*b.y - a.y*b.x; } int getM( Vector2D a ) { return abs(a.x) + abs(a.y); } bool collision( PVector2D t, Vector2D p ) { for ( int i = 0; i < 3; i++ ) { int ii = i; int kk = (i+2)%3; int c = cross( t[ii]-t[kk], p-t[kk] ); if ( c == 0 && getM( p-t[kk] ) <= getM( t[ii]-t[kk] ) ) { return true; } } for ( int i = 0; i < 3; i++ ) { int ii = i; int jj = (i+1)%3; int kk = (i+2)%3; int c1 = cross( t[ii]-t[kk], p-t[kk] ); int c2 = cross( t[jj]-t[kk], p-t[kk] ); if ( ( c1 > 0 && c2 > 0 ) || ( c1 < 0 && c2 < 0 ) ) return false; } return true; } bool collision( int a, int b ) { PVector2D ta = getTriangleA( a ); PVector2D tb = getTriangleB( b ); for ( int i = 0; i < 3; i++ ) { if ( collision( ta, tb[i] ) ) return true; if ( collision( tb, ta[i] ) ) return true; } for ( int i = 0; i < 3; i++ ) { for ( int j = 0; j < 3; j++ ) { if ( ta[i] == tb[j] ) return true; } } return false; } int main() { int n; while ( cin >> n && n ) { for ( int i = 0; i < n; i++ ) { initF(); initQ(); int m; cin >> m; for ( int j = 0; j < m; j++ ) { inputQ(); F[FC++] = -1; } for ( int ii = 0; ii < m; ii++ ) { for ( int jj = 0; jj < m; jj++ ) { if ( same( ii, jj ) ) continue; if ( collision( ii, jj ) ) merge( ii, jj ); } } set <int> S; for ( int j = 0; j < m; j++ ) { S.insert( get(j) ); } cout << S.size() << endl; } } return 0; }
a.cc:2:10: fatal error: stdlib: No such file or directory 2 | #include <stdlib> | ^~~~~~~~ compilation terminated.
s564831194
p00214
C++
#include <iostream> #include <stdlib> #include <set> #include <memory> using namespace std; const int size = 101; const double eps = 1e-9; struct Vector2D { int x; int y; Vector2D(): x(0), y(0) {} Vector2D( int x, int y ): x(x), y(y) {} Vector2D operator -( Vector2D& right ) { return Vector2D( x-right.x, y-right.y ); } bool operator ==( Vector2D& right ) { return x == right.x && y == right.y; } }; typedef Vector2D* PVector2D; // ツ四ツ角ツ形ツデツーツタ int Q[size][8]; int QC; void initQ() { QC = 0; } void inputQ() { for ( int i = 0; i < 8; i++ ) { cin >> Q[QC][i]; } QC++; } // disjoint sets int F[size]; int FC; void initF() { FC = 0; } int get( int ind ) { return F[ind] == -1 ? ind : get( F[ind] ); } bool same( int a, int b ) { int fa = get( a ); int fb = get( b ); return fa == fb; } void merge( int a, int b ) { int fa = get( a ); int fb = get( b ); if ( fa != fb ) { F[fb] = fa; } } // PVector2D getTriangleA( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][0], Q[a][1] ); answer[1] = Vector2D( Q[a][2], Q[a][3] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } PVector2D getTriangleB( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][2], Q[a][3] ); answer[1] = Vector2D( Q[a][4], Q[a][5] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } int cross( Vector2D a, Vector2D b ) { return a.x*b.y - a.y*b.x; } int getM( Vector2D a ) { return a.x + a.y; } bool collision( PVector2D t, Vector2D p ) { for ( int i = 0; i < 3; i++ ) { int ii = i; int kk = (i+2)%3; int c = cross( t[ii]-t[kk], p-t[kk] ); if ( c == 0 && getM( p-t[kk] ) <= getM( t[ii]-t[kk] ) ) { return true; } } for ( int i = 0; i < 3; i++ ) { int ii = i; int jj = (i+1)%3; int kk = (i+2)%3; int c1 = cross( t[ii]-t[kk], p-t[kk] ); int c2 = cross( t[jj]-t[kk], p-t[kk] ); if ( ( c1 > 0 && c2 > 0 ) || ( c1 < 0 && c2 < 0 ) ) return false; } return true; } bool collision( int a, int b ) { PVector2D ta = getTriangleA( a ); PVector2D tb = getTriangleB( b ); for ( int i = 0; i < 3; i++ ) { if ( collision( ta, tb[i] ) ) return true; if ( collision( tb, ta[i] ) ) return true; } for ( int i = 0; i < 3; i++ ) { for ( int j = 0; j < 3; j++ ) { if ( ta[i] == tb[j] ) return true; } } return false; } int main() { int n; while ( cin >> n && n ) { for ( int i = 0; i < n; i++ ) { initF(); initQ(); int m; cin >> m; for ( int j = 0; j < m; j++ ) { inputQ(); F[FC++] = -1; } for ( int ii = 0; ii < m; ii++ ) { for ( int jj = 0; jj < m; jj++ ) { if ( same( ii, jj ) ) continue; if ( collision( ii, jj ) ) merge( ii, jj ); } } set <int> S; for ( int j = 0; j < m; j++ ) { S.insert( get(j) ); } cout << S.size() << endl; } } return 0; }
a.cc:2:10: fatal error: stdlib: No such file or directory 2 | #include <stdlib> | ^~~~~~~~ compilation terminated.
s549427612
p00214
C++
#include <iostream> #include <stdlib> #include <set> #include <memory> using namespace std; const int size = 101; const double eps = 1e-9; struct Vector2D { int x; int y; Vector2D(): x(0), y(0) {} Vector2D( int x, int y ): x(x), y(y) {} Vector2D operator -( Vector2D& right ) { return Vector2D( x-right.x, y-right.y ); } bool operator ==( Vector2D& right ) { return x == right.x && y == right.y; } }; typedef Vector2D* PVector2D; // ツ四ツ角ツ形ツデツーツタ int Q[size][8]; int QC; void initQ() { QC = 0; } void inputQ() { for ( int i = 0; i < 8; i++ ) { cin >> Q[QC][i]; } QC++; } // disjoint sets int F[size]; int FC; void initF() { FC = 0; } int get( int ind ) { return F[ind] == -1 ? ind : get( F[ind] ); } bool same( int a, int b ) { int fa = get( a ); int fb = get( b ); return fa == fb; } void merge( int a, int b ) { int fa = get( a ); int fb = get( b ); if ( fa != fb ) { F[fb] = fa; } } // PVector2D getTriangleA( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][0], Q[a][1] ); answer[1] = Vector2D( Q[a][2], Q[a][3] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } PVector2D getTriangleB( int a ) { PVector2D answer = new Vector2D[3]; answer[0] = Vector2D( Q[a][2], Q[a][3] ); answer[1] = Vector2D( Q[a][4], Q[a][5] ); answer[2] = Vector2D( Q[a][6], Q[a][7] ); return answer; } int cross( Vector2D a, Vector2D b ) { return a.x*b.y - a.y*b.x; } int getM( Vector2D a ) { return abs(a.x) + abs(a.y); } bool collision( PVector2D t, Vector2D p ) { for ( int i = 0; i < 3; i++ ) { int ii = i; int kk = (i+2)%3; int c = cross( t[ii]-t[kk], p-t[kk] ); //if ( c == 0 && getM( p-t[kk] ) <= getM( t[ii]-t[kk] ) ) { // return true; //} } for ( int i = 0; i < 3; i++ ) { int ii = i; int jj = (i+1)%3; int kk = (i+2)%3; int c1 = cross( t[ii]-t[kk], p-t[kk] ); int c2 = cross( t[jj]-t[kk], p-t[kk] ); if ( ( c1 > 0 && c2 > 0 ) || ( c1 < 0 && c2 < 0 ) ) return false; } return true; } bool collision( int a, int b ) { PVector2D ta = getTriangleA( a ); PVector2D tb = getTriangleB( b ); for ( int i = 0; i < 3; i++ ) { if ( collision( ta, tb[i] ) ) return true; if ( collision( tb, ta[i] ) ) return true; } for ( int i = 0; i < 3; i++ ) { for ( int j = 0; j < 3; j++ ) { if ( ta[i] == tb[j] ) return true; } } return false; } int main() { int n; while ( cin >> n && n ) { for ( int i = 0; i < n; i++ ) { initF(); initQ(); int m; cin >> m; for ( int j = 0; j < m; j++ ) { inputQ(); F[FC++] = -1; } for ( int ii = 0; ii < m; ii++ ) { for ( int jj = 0; jj < m; jj++ ) { if ( same( ii, jj ) ) continue; if ( collision( ii, jj ) ) merge( ii, jj ); } } set <int> S; for ( int j = 0; j < m; j++ ) { S.insert( get(j) ); } cout << S.size() << endl; } } return 0; }
a.cc:2:10: fatal error: stdlib: No such file or directory 2 | #include <stdlib> | ^~~~~~~~ compilation terminated.
s106224811
p00214
C++
#include<iostream> #include<complex> #include<algorithm> #define EPS 1e-10 using namespace std; typedef complex<double> P; int n,m; P p[100][4]; double cross(P a,P b){return imag(conj(a)*b);} double dot(P a,P b){return real(conj(a)*b);} bool interp(int q,P x){ P tmp = P(10000,x.imag()); bool res = false; for(int i=0;i<4;i++)if(is_cp(p[q][i],p[q][(i+1)%4],x,tmp))res=!res; return res; } int ccw(P a,P b,P c){ b -= a;c -= a; if (cross(b,c)>EPS) return 1; if (cross(b,c)<-EPS) return -1; if (dot(b, c)<-EPS) return 2; if (abs(b)<abs(c)) return -2; return 0; } bool is_cp(P a1, P a2, P b1, P b2){ return ( ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 && ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0 ); } /* bool interp(int q, P x){ for(int i=0;i<4;i++){ if ( ccw(p[q][i], p[q][(i+1)%4], x ) == 1 ) return false; } return true; } */ bool inter(int q1,int q2){ for(int i=0;i<4;i++) for(int j=0;j<4;j++) if(is_cp(p[q1][i],p[q1][(i+1)%4],p[q2][j],p[q2][(j+1)%4]))return true; for(int i=0;i<4;i++)if(interp(q1,p[q2][i]))return true; for(int i=0;i<4;i++)if(interp(q2,p[q1][i]))return true; return false; } int par[100]; int rank[100]; void init(int n){ for(int i=0;i<n;i++){ par[i] = i; rank[i] = 0; } } int find(int x){ if(par[x] == x)return x; return par[x] = find(par[x]); } void unite(int x,int y){ x = find(x); y = find(y); if(x==y)return; if(rank[x] < rank[y])par[x] = y; else{ par[y] = x; if(rank[x] == rank[y])rank[x]++; } } int main(){ while(cin >> n && n){ for(int i=0;i<n;i++){ cin >> m; for(int j=0;j<m;j++) for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); init(m); for(int j=0;j<m;j++) for(int k=0;k<j;k++) for(int l=0;l<4;l++) if(inter(j,k))unite(j,k); int ans = 0; for(int j=0;j<m;j++){ find(j); if(par[j]==j)ans++; } cout << ans << endl; } } }
a.cc: In function 'bool interp(int, P)': a.cc:19:26: error: 'is_cp' was not declared in this scope 19 | for(int i=0;i<4;i++)if(is_cp(p[q][i],p[q][(i+1)%4],x,tmp))res=!res; | ^~~~~ a.cc: In function 'void init(int)': a.cc:59:5: error: reference to 'rank' is ambiguous 59 | rank[i] = 0; | ^~~~ In file included from /usr/include/c++/14/bits/move.h:37, from /usr/include/c++/14/bits/exception_ptr.h:41, from /usr/include/c++/14/exception:166, from /usr/include/c++/14/ios:41, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:54:5: note: 'int rank [100]' 54 | int rank[100]; | ^~~~ a.cc: In function 'void unite(int, int)': a.cc:73:6: error: reference to 'rank' is ambiguous 73 | if(rank[x] < rank[y])par[x] = y; | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:54:5: note: 'int rank [100]' 54 | int rank[100]; | ^~~~ a.cc:73:16: error: reference to 'rank' is ambiguous 73 | if(rank[x] < rank[y])par[x] = y; | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:54:5: note: 'int rank [100]' 54 | int rank[100]; | ^~~~ a.cc:76:8: error: reference to 'rank' is ambiguous 76 | if(rank[x] == rank[y])rank[x]++; | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:54:5: note: 'int rank [100]' 54 | int rank[100]; | ^~~~ a.cc:76:19: error: reference to 'rank' is ambiguous 76 | if(rank[x] == rank[y])rank[x]++; | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:54:5: note: 'int rank [100]' 54 | int rank[100]; | ^~~~ a.cc:76:27: error: reference to 'rank' is ambiguous 76 | if(rank[x] == rank[y])rank[x]++; | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:54:5: note: 'int rank [100]' 54 | int rank[100]; | ^~~~ a.cc: In function 'int main()': a.cc:85:33: error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'double') 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~ ^~ ~~~~~~~~~~~~~~ | | | | | double | std::istream {aka std::basic_istream<char>} In file included from /usr/include/c++/14/iostream:42: /usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 170 | operator>>(bool& __n) | ^~~~~~~~ /usr/include/c++/14/istream:170:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match) 174 | operator>>(short& __n); | ^~~~~~~~ /usr/include/c++/14/istream:174:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 177 | operator>>(unsigned short& __n) | ^~~~~~~~ /usr/include/c++/14/istream:177:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'short unsigned int&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match) 181 | operator>>(int& __n); | ^~~~~~~~ /usr/include/c++/14/istream:181:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 184 | operator>>(unsigned int& __n) | ^~~~~~~~ /usr/include/c++/14/istream:184:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'unsigned int&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 188 | operator>>(long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:188:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'long int&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 192 | operator>>(unsigned long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:192:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 199 | operator>>(long long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:199:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 203 | operator>>(unsigned long long& __n) | ^~~~~~~~ /usr/include/c++/14/istream:203:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'long long unsigned int&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:219:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match) 219 | operator>>(float& __f) | ^~~~~~~~ /usr/include/c++/14/istream:219:7: note: conversion of argument 1 would be ill-formed: a.cc:85:48: error: cannot bind non-const lvalue reference of type 'float&' to a value of type 'double' 85 | for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag(); | ~~~~~~~~~~~~^~ /usr/include/c++/14/istream:223:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istrea
s737618235
p00214
C++
#include <set> #include <cstdio> #include <queue> #include <iostream> #include <complex> #include <vector> #include <climits> #include <cfloat> #define REP(i,n) for(int i=0; i<(int)(n); i++) using namespace std; typedef complex<double> P; typedef vector<P> Polygon; const double EPS = 1e-10; class UnionFind{ private: vector<int> id; int getId(int i){ if(i == id[i]) return i; return id[i] = getId(id[i]); } public: UnionFind(int size = 0){ init(size); } ~UnionFind(){} void init(int size){ id = vector<int>(size); for(int i = 0; i < size; i++) id[i] = i; } void unite(int i, int j){ int next = min( getId(i), getId(j) ); id[getId(i)] = id[getId(j)] = next; } int operator [](int i){ return getId(i); } int count(){ set<int> s; for(int i = 0; i < (int)id.size(); i++) s.insert(getId(i)); return s.size(); } }; struct S{ P p1; P p2; S(P p,P q) : p1(p), p2(q) {} }; bool intersect(const S &s, const P &p){ return std::abs(abs(s.p1 - p) + abs(s.p2 - p) - abs } bool contain(const Polygon &g, const P &p){ double sum = 0.0; int n = g.size(); for(int i = 0; i < n; i++){ int j = (i + 1) % n; if(intersect(S(g[i], g[j]), p)) return true; sum += arg((g[j] - p) / (g[i] - p)); } return std::abs(sum) > 1.0; // 0 or 2 PI } bool intersect(const Polygon &p1, const Polygon &p2){ int n = p2.size(); int m = p1.size(); for(int i = 0; i < n; i++) if(contain(p1, p2[i])) return true; for(int i = 0; i < m; i++) if(contain(p2, p1[i])) return true; return false; } int main(){ int t; while(scanf("%d", &t), t){ while(t --> 0){ int n; scanf("%d", &n); UnionFind uf(n); vector<Polygon> ps(n); REP(i,n){ vector<P> pos(4); REP(j,4) scanf("%lf%lf", &pos[j].real(), &pos ps[i] = pos; REP(j,i) if(intersect(ps[i], ps[j])){ //printf("cross: %d %d\n", i, j); uf.unite(i, j); } } printf("%d\n", uf.count()); } } return 0; }
a.cc: In function 'bool intersect(const S&, const P&)': a.cc:54:49: error: invalid operands of types 'double' and '<unresolved overloaded function type>' to binary 'operator-' 54 | return std::abs(abs(s.p1 - p) + abs(s.p2 - p) - abs | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ a.cc:54:54: error: expected ';' before '}' token 54 | return std::abs(abs(s.p1 - p) + abs(s.p2 - p) - abs | ^ | ; 55 | } | ~ a.cc: In function 'int main()': a.cc:89:46: error: lvalue required as unary '&' operand 89 | REP(j,4) scanf("%lf%lf", &pos[j].real(), &pos | ~~~~~~~~~~~^~ a.cc:89:54: error: expected ')' before 'ps' 89 | REP(j,4) scanf("%lf%lf", &pos[j].real(), &pos | ~ ^ | ) 90 | ps[i] = pos; | ~~
s968303517
p00214
C++
#include<cmath> #include<algorithm> #include<iostream> #include<vector> #include<climits> #include<cfloat> using namespace std; double EPS = 1e-10; const double PI = acos(-1); double add(double a, double b){ if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0; return a+b; } struct point{ double x, y; point(){} point(double x,double y) : x(x) , y(y){} point operator + (point p){ return point(add(x,p.x), add(y,p.y)); } point operator - (point p){ return point(add(x,-p.x), add(y,-p.y)); } point operator * (double d){ return point(x*d,y*d); } point operator / (double d){ return point(x/d,y/d); } bool operator == ( const point &p ) const { return abs(x-p.x) < EPS && abs(y-p.y) < EPS; } }; double dot(point a, point b) { return (a.x * b.x + a.y * b.y); } double cross(point a, point b) { return (a.x * b.y - a.y * b.x); } int is_point_on_line(point a, point b, point c) { return cross(a-c, b-c)==0 && dot(a-c, b-c)<=0; } int is_intersected_ls(point a1, point a2, point b1, point b2) { if(cross(a1-a2,b1-b2)==0){ return is_point_on_line(a1,a2,b1) || is_point_on_line(a1,a2,b2) || is_point_on_line(b1,b2,a1) || is_point_on_line(b1,b2,a2); } else { return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) && ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS ); } } int inside(point p, vector<point> ps){ point a,b; a=b=p; b.x=DBL_MAX; n=ps.size(); ps.push_back(ps[0]); double ymx=-DBL_MAX,ymn=DBL_MAX; for(int i=0;i<n;i++){ ymx=max(ymx,ps[i].y); ymn=min(ymn,ps[i].y); } if(a.y<=ymn||a.y>=ymx)return 0; for(int i=0;i<n;i++){ if(is_point_on_line(ps[i],ps[i+1],p))return 1; } int cnt1=0; for(int i=0;i<n;i++) if(is_point_on_line(a,b,ps[i]))cnt1++; int cnt=0; for(int i=0;i<n;i++) if(is_intersected_ls(ps[i],ps[i+1],a,b))cnt++; return (cnt-cnt1)%2; } int crossPol(vector<point> pol1, vector<point> pol2){ int szpol1=pol1.size(); int szpol2=pol2.size(); for(int i=0;i<szpol1;i++) if(inside(pol1[i],pol2,szpol2))return 1; for(int i=0;i<szpol2;i++) if(inside(pol2[i],pol1,szpol1))return 1; pol1.push_back(pol1[0]); pol2.push_back(pol2[0]); for(int i=0;i<szpol1;i++) for(int j=0;j<szpol2;j++) if(is_intersected_ls(pol1[i],pol1[i+1],pol2[j],pol2[j+1]))return 1; return 0; } int gr[101][101],fg[101],m; void dfs(int j){ fg[j]=1; for(int k=0;k<m;k++) if(gr[j][k]==1 && !fg[k])dfs(k); } int main(void){ int n; point a; vector<point>pol[101]; while(cin >> n,n){ for(int i=0;i<n;i++){ cin >> m; for(int i=0;i<101;i++)pol[i].clear(); for(int i=0;i<101;i++){ for(int j=0;j<101;j++){ gr[i][j]=0; } fg[i]=0; } for(int j=0;j<m;j++){ for(int k=0;k<4;k++){ cin >> a.x >> a.y; pol[j].push_back(a); } } for(int j=0;j<m;j++){ for(int k=0;k<m;k++){ if(j!=k && crossPol(pol[j],pol[k]))gr[j][k]=gr[k][j]=1; } } int cnt=0; for(int j=0;j<m;j++){ if(fg[j]==0){ dfs(j); cnt++; } } cout << cnt << endl; } } return 0; }
a.cc: In function 'int inside(point, std::vector<point>)': a.cc:72:3: error: 'n' was not declared in this scope 72 | n=ps.size(); | ^ a.cc: In function 'int crossPol(std::vector<point>, std::vector<point>)': a.cc:101:14: error: too many arguments to function 'int inside(point, std::vector<point>)' 101 | if(inside(pol1[i],pol2,szpol2))return 1; | ~~~~~~^~~~~~~~~~~~~~~~~~~~~ a.cc:68:5: note: declared here 68 | int inside(point p, vector<point> ps){ | ^~~~~~ a.cc:104:14: error: too many arguments to function 'int inside(point, std::vector<point>)' 104 | if(inside(pol2[i],pol1,szpol1))return 1; | ~~~~~~^~~~~~~~~~~~~~~~~~~~~ a.cc:68:5: note: declared here 68 | int inside(point p, vector<point> ps){ | ^~~~~~
s528371071
p00214
C++
#include<cmath> #include<algorithm> #include<iostream> #include<vector> #include<climits> #include<cfloat> using namespace std; double EPS = 1e-10; const double PI = acos(-1); double add(double a, double b){ if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0; return a+b; } struct point{ double x, y; point(){} point(double x,double y) : x(x) , y(y){} point operator + (point p){ return point(add(x,p.x), add(y,p.y)); } point operator - (point p){ return point(add(x,-p.x), add(y,-p.y)); } point operator * (double d){ return point(x*d,y*d); } point operator / (double d){ return point(x/d,y/d); } bool operator == ( const point &p ) const { return abs(x-p.x) < EPS && abs(y-p.y) < EPS; } }; double dot(point a, point b) { return (a.x * b.x + a.y * b.y); } double cross(point a, point b) { return (a.x * b.y - a.y * b.x); } int is_point_on_line(point a, point b, point c) { return cross(a-c, b-c)==0 && dot(a-c, b-c)<=0; } int is_intersected_ls(point a1, point a2, point b1, point b2) { if(cross(a1-a2,b1-b2)==0){ return is_point_on_line(a1,a2,b1) || is_point_on_line(a1,a2,b2) || is_point_on_line(b1,b2,a1) || is_point_on_line(b1,b2,a2); } else { return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) && ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS ); } } int inside(point p, vector<point> ps){ point a,b; a=b=p; b.x=DBL_MAX; n=ps.size(); ps.push_back(ps[0]); double ymx=-DBL_MAX,ymn=DBL_MAX; for(int i=0;i<n;i++){ ymx=max(ymx,ps[i].y); ymn=min(ymn,ps[i].y); } if(a.y<=ymn||a.y>=ymx)return 0; for(int i=0;i<n;i++){ if(is_point_on_line(ps[i],ps[i+1],p))return 1; } int cnt1=0; for(int i=0;i<n;i++) if(is_point_on_line(a,b,ps[i]))cnt1++; int cnt=0; for(int i=0;i<n;i++) if(is_intersected_ls(ps[i],ps[i+1],a,b))cnt++; return (cnt-cnt1)%2; } int crossPol(vector<point> pol1, vector<point> pol2){ int szpol1=pol1.size(); int szpol2=pol2.size(); for(int i=0;i<szpol1;i++) if(inside(pol1[i],pol2))return 1; for(int i=0;i<szpol2;i++) if(inside(pol2[i],pol1))return 1; pol1.push_back(pol1[0]); pol2.push_back(pol2[0]); for(int i=0;i<szpol1;i++) for(int j=0;j<szpol2;j++) if(is_intersected_ls(pol1[i],pol1[i+1],pol2[j],pol2[j+1]))return 1; return 0; } int gr[101][101],fg[101],m; void dfs(int j){ fg[j]=1; for(int k=0;k<m;k++) if(gr[j][k]==1 && !fg[k])dfs(k); } int main(void){ int n; point a; vector<point>pol[101]; while(cin >> n,n){ for(int i=0;i<n;i++){ cin >> m; for(int i=0;i<101;i++)pol[i].clear(); for(int i=0;i<101;i++){ for(int j=0;j<101;j++){ gr[i][j]=0; } fg[i]=0; } for(int j=0;j<m;j++){ for(int k=0;k<4;k++){ cin >> a.x >> a.y; pol[j].push_back(a); } } for(int j=0;j<m;j++){ for(int k=0;k<m;k++){ if(j!=k && crossPol(pol[j],pol[k]))gr[j][k]=gr[k][j]=1; } } int cnt=0; for(int j=0;j<m;j++){ if(fg[j]==0){ dfs(j); cnt++; } } cout << cnt << endl; } } return 0; }
a.cc: In function 'int inside(point, std::vector<point>)': a.cc:72:3: error: 'n' was not declared in this scope 72 | n=ps.size(); | ^
s939508901
p00214
C++
EPS = 1e-9 class Point attr_accessor :x, :y def initialize(x = 0, y = 0) @x = x @y = y end def +(right) Point.new(@x + right.x, @y + right.y) end def -(right) Point.new(@x - right.x, @y - right.y) end def [](idx) idx == 0 ? @x : @y end def []=(idx, val) @x = val if idx == 0 @y = val if idx == 1 end end class Tetragon attr_accessor :points def initialize() @points = Array.new(4){ Point.new } end def [](idx) @points[idx] end end def dot(a, b) a.x * b.x + a.y * b.y end def cross(a, b) a.x * b.y - b.x * a.y end def is_intersected_ls(a1, a2, b1, b2) cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS and cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS end def cont(tet, pnt) area = cross(tet[1] - tet[0], tet[2] - tet[0]).abs + cross(tet[1] - tet[3], tet[2] - tet[3]).abs 4.times{ |i| area -= cross(tet[i] - pnt, tet[(i+1)%4] - pnt).abs } area.abs < EPS end def col(a, b) 4.times{ |i| return true if cont(a, b[i]) or cont(b, a[i]) } 4.times{ |i| 4.times{ |j| return true if is_intersected_ls(a[i], a[(i+1)%4], b[j], b[(j+1)%4]) } } false end class UnionFind def initialize(size) @data = Array.new(size, -1) end def unite(a, b) a = root(a); b = root(b) if(a != b) a, b = b, a if @data[b] < @data[a] @data[a] += @data[b]; @data[b] = a end a != b end def same(a, b) root(a) == root(b) end def root(a) @data[a] < 0 ? a : @data[a] = root(@data[a]) end def size(a) -@data[root(a)] end def count @data.count{ |val| val < 0 } end end while n = gets.chomp.to_i and n != 0 n.times do m = gets.chomp.to_i tetras = Array.new(m){ Tetragon.new } m.times{ |i| gets.split(" ").map(&:to_i).each_with_index{ |j, k| tetras[i][k / 2][k % 2] = j } } uft = UnionFind.new(m) m.times{ |i| m.times{ |j| uft.unite(i, j) if col(tetras[i], tetras[j]) } } puts uft.count end end
a.cc:6:5: error: stray '@' in program 6 | @x = x | ^ a.cc:7:5: error: stray '@' in program 7 | @y = y | ^ a.cc:11:15: error: stray '@' in program 11 | Point.new(@x + right.x, @y + right.y) | ^ a.cc:11:29: error: stray '@' in program 11 | Point.new(@x + right.x, @y + right.y) | ^ a.cc:14:15: error: stray '@' in program 14 | Point.new(@x - right.x, @y - right.y) | ^ a.cc:14:29: error: stray '@' in program 14 | Point.new(@x - right.x, @y - right.y) | ^ a.cc:17:16: error: stray '@' in program 17 | idx == 0 ? @x : @y | ^ a.cc:17:21: error: stray '@' in program 17 | idx == 0 ? @x : @y | ^ a.cc:20:5: error: stray '@' in program 20 | @x = val if idx == 0 | ^ a.cc:21:5: error: stray '@' in program 21 | @y = val if idx == 1 | ^ a.cc:28:5: error: stray '@' in program 28 | @points = Array.new(4){ Point.new } | ^ a.cc:31:5: error: stray '@' in program 31 | @points[idx] | ^ a.cc:65:5: error: stray '@' in program 65 | @data = Array.new(size, -1) | ^ a.cc:70:22: error: stray '@' in program 70 | a, b = b, a if @data[b] < @data[a] | ^ a.cc:70:33: error: stray '@' in program 70 | a, b = b, a if @data[b] < @data[a] | ^ a.cc:71:7: error: stray '@' in program 71 | @data[a] += @data[b]; @data[b] = a | ^ a.cc:71:19: error: stray '@' in program 71 | @data[a] += @data[b]; @data[b] = a | ^ a.cc:71:29: error: stray '@' in program 71 | @data[a] += @data[b]; @data[b] = a | ^ a.cc:79:5: error: stray '@' in program 79 | @data[a] < 0 ? a : @data[a] = root(@data[a]) | ^ a.cc:79:24: error: stray '@' in program 79 | @data[a] < 0 ? a : @data[a] = root(@data[a]) | ^ a.cc:79:40: error: stray '@' in program 79 | @data[a] < 0 ? a : @data[a] = root(@data[a]) | ^ a.cc:82:6: error: stray '@' in program 82 | -@data[root(a)] | ^ a.cc:85:5: error: stray '@' in program 85 | @data.count{ |val| val < 0 } | ^ a.cc:1:1: error: 'EPS' does not name a type 1 | EPS = 1e-9 | ^~~ a.cc:29:3: error: 'end' does not name a type 29 | end | ^~~ a.cc:52:3: error: 'area' does not name a type 52 | area.abs < EPS | ^~~~ a.cc:58:3: error: expected unqualified-id before numeric constant 58 | 4.times{ |i| 4.times{ |j| return true if is_intersected_ls(a[i], a[(i+1)%4], b[j], b[(j+1)%4]) } } | ^~~~~~~ a.cc:60:3: error: expected unqualified-id before 'false' 60 | false | ^~~~~ a.cc:68:18: error: 'b' does not name a type 68 | a = root(a); b = root(b) | ^ a.cc:71:30: error: 'data' does not name a type 71 | @data[a] += @data[b]; @data[b] = a | ^~~~ a.cc:86:3: error: 'end' does not name a type 86 | end | ^~~ a.cc:95:5: error: 'm' does not name a type 95 | m.times{ |i| gets.split(" ").map(&:to_i).each_with_index{ |j, k| tetras[i][k / 2][k % 2] = j } } | ^ a.cc:97:5: error: 'uft' does not name a type 97 | uft = UnionFind.new(m) | ^~~ a.cc:101:5: error: 'puts' does not name a type 101 | puts uft.count | ^~~~
s699929963
p00214
C++
#include<iostream> #include<vector> #include<algorithm> #include<set> const double EPS = 1e-24; struct P{ double x, y; P operator-(const P& rp); bool operator==(const P& rp); }; P P::operator-(const P& rp){ return {x-rp.x, y-rp.y}; } bool P::operator==(const P& rp){ return abs(x-rp.x) < EPS && abs(y-rp.y) < EPS; } typedef P Vector; double dotProduct(Vector v1, Vector v2){ return v1.x * v1.y + v2.x * v2.y; } double crossProduct(Vector v1, Vector v2){ return v1.x * v2.y - v2.x * v1.y; } double abs(P p){ return sqrt(p.x * p.x + p.y * p.y); } struct Rectangle{ P ps[4]; }; class UnionFind{ public: int size; std::vector<int> par, rank; UnionFind(int _size); int find(int x); void unite(int x, int y); }; UnionFind::UnionFind(int _size) :par(_size), rank(_size), size(_size){ for(int i=0;i<size;i++){ par[i] = i; rank[i] = 0; } } int UnionFind::find(int x){ if(par[x] == x){ return x; } return par[x] = find(par[x]); } void UnionFind::unite(int x, int y){ x = find(x); y = find(y); if(x == y)return;//もう併合している if(rank[x] < rank[y]){ par[x] = par[y]; }else{ par[y] = par[x]; if(rank[x] == rank[y]){ rank[x]++; } } } bool kousa(Rectangle r1, Rectangle r2){ for(int k=2;k;k--){ for(int i=0;i<4;i++){ P c = r1.ps[i]; int count = 0; for(int j=0;j<4;j++){ P a = r2.ps[j], b = r2.ps[(j+1)%4]; if(a == c || b == c || (abs(crossProduct(b-a, c-a)) < EPS) && dotProduct(b-a, c-a) > -EPS && abs(b-a) < abs(c-a) + EPS){//四角形の線分上 return true; } if(crossProduct(b-a, c-a) > -EPS){ count++; }else{ count--; } } if(abs(count) == 4){ return true; } } std::swap(r1, r2); } return false; } int main(){ int n; while(std::cin >> n, n){ int res[100]; for(int k=0;k<n;k++){ int m; std::cin >> m; Rectangle rs[100]; for(int i=0;i<m;i++){ P (&ps)[4] = rs[i].ps; for(int j=0;j<4;j++){ std::cin >> ps[j].x >> ps[j].y; } } UnionFind uf(100); for(int i=0;i<m;i++){ for(int j=i+1;j<m;j++){ if(kousa(rs[i], rs[j])){//片方灯せばいいかなー uf.unite(i, j);//併合 } } } std::set<int> s;//大元さん for(int i=0;i<m;i++){ s.insert(uf.find(i)); } std::cout << s.size() << std::endl; } } }
a.cc: In function 'double abs(P)': a.cc:33:16: error: 'sqrt' was not declared in this scope 33 | return sqrt(p.x * p.x + p.y * p.y); | ^~~~
s552551662
p00215
Java
### constant MAX_INT = (1 << 31) - 1 ### subroutines def dist(nd0, nd1) (nd0[0] - nd1[0]).abs + (nd0[1] - nd1[1]).abs end ### main while true w, h = gets.strip.split(' ').map{|s| s.to_i} break if w == 0 && h == 0 nodes = 7.times.map{[]} start = nil goal = nil for y in (0...h) hl = gets.strip.split('') for x in (0...w) case hl[x] when 'S' start = [x, y, 0] nodes[5] << start when 'G' goal = [x, y, MAX_INT] nodes[6] << goal when '1'..'5' attr = hl[x].to_i - 1 nodes[attr] << [x, y, MAX_INT] end end end min_dist = MAX_INT min_attr = nil for sattr in (0..4) attrs = [5] + (1..4).map{|k| (sattr + k) % 5} + [6] start[2] = 0 goal[2] = MAX_INT for k in (1..5) prev_attr = attrs[k - 1] attr0 = attrs[k] for nd0 in nodes[attr0] min_dist0 = MAX_INT for p_nd in nodes[prev_attr] d = p_nd[2] + dist(p_nd, nd0) min_dist0 = d if min_dist0 > d end nd0[2] = min_dist0 end end if goal[2] < MAX_INT && min_dist > goal[2] min_dist = goal[2] min_attr = sattr end end if min_attr.nil? puts 'NA' else puts [min_attr + 1, min_dist].join(' ') end end
Main.java:1: error: illegal character: '#' ### constant ^ Main.java:1: error: illegal character: '#' ### constant ^ Main.java:1: error: illegal character: '#' ### constant ^ Main.java:3: error: class, interface, enum, or record expected MAX_INT = (1 << 31) - 1 ^ Main.java:5: error: illegal character: '#' ### subroutines ^ Main.java:5: error: illegal character: '#' ### subroutines ^ Main.java:5: error: illegal character: '#' ### subroutines ^ Main.java:11: error: illegal character: '#' ### main ^ Main.java:11: error: illegal character: '#' ### main ^ Main.java:11: error: illegal character: '#' ### main ^ Main.java:21: error: illegal '.' for y in (0...h) ^ Main.java:22: error: empty character literal hl = gets.strip.split('') ^ Main.java:23: error: illegal '.' for x in (0...w) ^ Main.java:31: error: illegal '.' when '1'..'5' ^ Main.java:69: error: unclosed character literal puts 'NA' ^ Main.java:69: error: illegal line end in character literal puts 'NA' ^ 16 errors
s315339681
p00215
Java
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Comparator; class Point{ public static int nextId = 0; public int id; public int x; public int y; /** ???????????????????????????0?4??????????????????-1???S???G??? */ public int type; public int distanceFromStart; public List<Point> nextPointList; public Point(int x, int y, int type) { this.id = nextId++; this.x = x; this.y = y; this.type = type; this.distanceFromStart = Integer.MAX_VALUE; } public int distance(Point p) { return Math.abs(this.x - p.x) + Math.abs(this.y - p.y); } } public class Main { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static Point start = null; public static Point goal = null; //????????¢???????????????????????????????????? public static List<List<Point> > pointListByType = new ArrayList<List<Point> >(); public static List<Point> firePointList; public static List<Point> icePointList; public static List<Point> treePointList; public static List<Point> earthPointList; public static List<Point> waterPointList; static { // ???????????¨??? for(int i = 0; i < 5; i++) { pointListByType.add(new ArrayList<Point>()); } } public static void main(String args[]) throws IOException { while(true) { String mapSizeStr = br.readLine(); if("0 0".equals(mapSizeStr)) break; String[] splittedStr = mapSizeStr.split(" "); int x = Integer.parseInt(splittedStr[0]); int y = Integer.parseInt(splittedStr[1]); for(List<Point> pointList : pointListByType) { pointList.clear(); } Point.nextId = 0; for(int r = 0; r < y; r++){ String line = br.readLine(); for(int c = 0; c < x; c++) { char pointLiteral = line.charAt(c); if(pointLiteral == 'S') { start = new Point(c, r, -1); start.nextPointList = new ArrayList<Point>(); start.distanceFromStart = 0; } else if(pointLiteral == 'G') { goal = new Point(c, r, -1); goal.nextPointList = null; } else if(pointLiteral != '.') { int type = (int)pointLiteral - (int)'1'; pointListByType.get(type).add(new Point(c, r, type)); } } } //??°?????????????????? //1??????????????¢????????????????±???§???2?????\???????????°?????°????????? int zeroTypeCount = 0; for(List<Point> pointList : pointListByType) { if(pointList.isEmpty()) { if(++zeroTypeCount >= 2) { break; } } } if(zeroTypeCount >= 2) { System.out.println("NA"); continue; } // ????±???§??????????????????????????? firePointList = pointListByType.get(0); icePointList = pointListByType.get(1); treePointList = pointListByType.get(2); earthPointList = pointListByType.get(3); waterPointList = pointListByType.get(4); /* // fire to ice for (Point p : firePointList) { p.nextPointList = icePointList; } // ice to tree for (Point p : icePointList) { p.nextPointList = treePointList; } // tree to earth for (Point p : treePointList) { p.nextPointList = earthPointList; } // earth to water for (Point p : earthPointList) { p.nextPointList = waterPointList; } // water to fire for (Point p : waterPointList) { p.nextPointList = firePointList; } */ // ????±???§???????????????????????´???????????????????????????????????????????±??????? int minLenType = -1; int minLen = Integer.MAX_VALUE; for (int firstType = 0; firstType < 5; firstType++) { //?????????????????\??????????????????????±???§????????????????????????????????´?????°????????? if( firstType == 0 && ( icePointList.isEmpty() || treePointList.isEmpty() || earthPointList.isEmpty() || waterPointList.isEmpty() ) || firstType == 1 && ( firePointList.isEmpty() || treePointList.isEmpty() || earthPointList.isEmpty() || waterPointList.isEmpty() ) || firstType == 2 && ( firePointList.isEmpty() || icePointList.isEmpty() || earthPointList.isEmpty() || waterPointList.isEmpty() ) || firstType == 3 && ( firePointList.isEmpty() || icePointList.isEmpty() || treePointList.isEmpty() || waterPointList.isEmpty() ) || firstType == 4 && ( firePointList.isEmpty() || icePointList.isEmpty() || treePointList.isEmpty() || earthPointList.isEmpty() ) ) { continue; } //?????????????????????????????????????????? //??????????????¶???????????§?????????????????????????????????????????? start.nextPointList.clear(); start.nextPointList.addAll(pointListByType.get((firstType + 1) % 5)); //?????????????????¢?´¢ int shortestPathLen = searchShortestPath(firstType); if(minLen > shortestPathLen) { minLen = shortestPathLen; minLenType = firstType; } // ?¨??????§??´??°??????????????????????????? for(List<Point> pointList : pointListByType) { for(Point p : pointList) { p.distanceFromStart = Integer.MAX_VALUE; } } goal.distanceFromStart = Integer.MAX_VALUE; } if(minLen == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println((minLenType + 1) + " " + minLen); } } } private static int searchShortestPath(int firstType) { int lastType = (firstType + 4) % 5; PriorityQueue<Point> q = new PriorityQueue<Point>( 5002, new Comparator<Point>() { @Override public int compare(Point p1, Point p2) { return p1.distanceFromStart - p2.distanceFromStart; } } ); q.add(start); Point searchingPoint = start; while(!q.isEmpty()) { //??????????????????????????¢???????°????????????????????????????????????? searchingPoint = q.poll(); if(searchingPoint.id == goal.id) break; if(searchingPoint.type == lastType) { int distance = searchingPoint.distance(goal); int searchinPointDistance = searchingPoint.distanceFromStart; if(goal.distanceFromStart > searchinPointDistance + distance) { goal.distanceFromStart = searchinPointDistance + distance; q.add(goal); } } else { //????´¢?????????????????????????????£????????????????????°??? List<Point> nextPointList = pointListByType.get((type + 1) % 5); for(Point tempNextPoint : nextPointList) { int distance = searchingPoint.distance(tempNextPoint); int searchinPointDistance = searchingPoint.distanceFromStart; if(tempNextPoint.distanceFromStart > searchinPointDistance + distance) { tempNextPoint.distanceFromStart = searchinPointDistance + distance; q.add(tempNextPoint); } } } } //??¢?´¢?????? return goal.distanceFromStart; } }
Main.java:236: error: cannot find symbol List<Point> nextPointList = pointListByType.get((type + 1) % 5); ^ symbol: variable type location: class Main 1 error
s301067533
p00215
Java
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Comparator; class Point{ public static int nextId = 0; public int id; public int x; public int y; public int type; public int distanceFromStart; public Point() { this(-1, -1, -1); } public Point(int x, int y, int type) { init(x, y, type); } public int distance(Point p) { return abs(this.x - p.x) + abs(this.y - p.y); } public void init(int x, int y, int type){ this.id = nextId++; this.x = x; this.y = y; this.type = type; this.distanceFromStart = Integer.MAX_VALUE; } private static int abs(int n) { int mask = n >> 31; return (n ^ mask) - mask; } } public class Main { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static Point start = new Point(); public static Point goal = new Point(); public static PriorityQueue<Point> q = new PriorityQueue<Point>( 5002, new Comparator<Point>() { @Override public int compare(Point p1, Point p2) { if(p1.distanceFromStart != p2.distanceFromStart) { return p1.distanceFromStart - p2.distanceFromStart; } return p1.distanceToGoal - p1.distanceToGoal; } } ); public static List<Point> allPachiCrePointList = new ArrayList<Point>(); public static List<List<Point> > pointListByType = new ArrayList<List<Point> >(); static { for(int i = 0; i < 5; i++) { pointListByType.add(new ArrayList<Point>()); } } public static void main(String args[]) throws IOException { while(true) { String mapSizeStr = br.readLine(); if("0 0".equals(mapSizeStr)) break; String[] splittedStr = mapSizeStr.split(" "); int x = Integer.parseInt(splittedStr[0]); int y = Integer.parseInt(splittedStr[1]); for(List<Point> pointList : pointListByType) { pointList.clear(); } Point.nextId = 0; for(int r = 0; r < y; r++){ String line = br.readLine(); char[] caray = line.toCharArray(); for(int c = 0; c < x; c++) { char pointLiteral = caray[c]; if(pointLiteral == 'S') { start.init(c, r, -1); start.distanceFromStart = 0; } else if(pointLiteral == 'G') { goal.init(c, r, -1); } else if(pointLiteral != '.') { int type = (int)pointLiteral - (int)'1'; Point p; if(allPachiCrePointList.size() <= Point.nextId) { p = new Point(c, r, type); } else { p = allPachiCrePointList.get(allPachiCrePointList.size() - 1); p.init(c, r, type); } pointListByType.get(type).add(p); } } } int minLenType = -1; int minLen = Integer.MAX_VALUE; for (int firstType = 0; firstType < 5; firstType++) { int shortestPathLen = searchShortestPath(firstType, minLen); if(minLen > shortestPathLen) { minLen = shortestPathLen; minLenType = firstType; } for(List<Point> pointList : pointListByType) { for(Point p : pointList) { p.distanceFromStart = Integer.MAX_VALUE; } } goal.distanceFromStart = Integer.MAX_VALUE; } if(minLen == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println((minLenType + 1) + " " + minLen); } } } private static int searchShortestPath(int firstType, int minLen) { int lastType = (firstType + 4) % 5; q.clear(); q.add(start); start.type = firstType; while(!q.isEmpty()) { Point searchingPoint = q.poll(); if(searchingPoint.id == goal.id) return goal.distanceFromStart; if(searchingPoint.distanceFromStart >= minLen) return Integer.MAX_VALUE; if(searchingPoint.type == lastType) { int distance = searchingPoint.distance(goal); int searchinPointDistance = searchingPoint.distanceFromStart; if(goal.distanceFromStart > searchinPointDistance + distance) { goal.distanceFromStart = searchinPointDistance + distance; q.add(goal); } } else { List<Point> nextPointList = pointListByType.get((searchingPoint.type + 1) % 5); int nextPointListSize = nextPointList.size(); for(int i = 0; i < nextPointListSize; i++) { Point tempNextPoint = nextPointList.get(i); int distance = searchingPoint.distance(tempNextPoint); int searchinPointDistance = searchingPoint.distanceFromStart; if(tempNextPoint.distanceFromStart > searchinPointDistance + distance) { tempNextPoint.distanceFromStart = searchinPointDistance + distance; q.add(tempNextPoint); } } } } return Integer.MAX_VALUE; } }
Main.java:60: error: cannot find symbol return p1.distanceToGoal - p1.distanceToGoal; ^ symbol: variable distanceToGoal location: variable p1 of type Point Main.java:60: error: cannot find symbol return p1.distanceToGoal - p1.distanceToGoal; ^ symbol: variable distanceToGoal location: variable p1 of type Point 2 errors
s728109220
p00215
Java
function main(){ var i = 0; while(true){ var fieldInfo = input[i].split(' '); var width = fieldInfo[0] - 0;//toInt var height = fieldInfo[1] - 0;//toInt // 0 0が入力された if(width == 0 && height == 0){ break; } var start; var goal; var elem = [[],[],[],[],[]]; for(var ei = 0;ei < 5; ei++){ elem[ei].length = 0; } for(var y = 0; y < height; y++){ i++;//1行進める for(var x = 0; x < width; x++){ var c = input[i][x]; switch(c){ case 'S': start = pos(x, y); break; case 'G': goal = pos(x, y); break; case '.': break; default : // 入力値が正しいので、絶対に属性 elem[c - 1][elem[c - 1].length] = pos(x, y); break; } } } var bestElement = -1; var distance = Infinity; // 属性ごとにループ for (var startElem = 0; startElem < 5; startElem++) { // DPの初期化 DP[属性][同じ属性内の連番] var dp = [[],[],[],[],[]]; for(var h = 0; h < 5; h++){ var hLength = elem[h].length; dp[h].length = hLength; for(var hidx = 0; hidx < hLength; hidx++){ dp[h][hidx] = Infinity; } } // 最初に選んだパチモンから次に捕まえられる属性番号 var first = (startElem + 1) >= 5 ? startElem - 4 : startElem + 1; var firstLength = elem[first].length; for (var j = 0; j < firstLength; j++) { // s→e1を計算 dp[first][j] = dist(start, elem[first][j]); } // s->1->2->3->4->g // なので、ループは間の-> * 3分まわす for (var e = 0; e < 3; e++) { // ex->e(x+1) var now = (first + e) >= 5 ? (first + e) - 5 : first + e; var next = (now + 1) == 5 ? now - 4 : now + 1; var nowLength = elem[now].length; var nextLength = elem[next].length; for (var j = 0; j < nowLength; j++) { for (var k = 0; k < nextLength; k++) { var d = dist(elem[now][j], elem[next][k]); if(d > dp[next][k]) continue; dp[next][k] = min(dp[next][k], dp[now][j] + d); } } } var last = (first + 3) % 5; var lastLength = elem[last].length; for (var j = 0; j < lastLength; j++) { // e4->g var d = dp[last][j] + dist(elem[last][j], goal); if (d < distance) { distance = d; bestElement = startElem + 1; } } } if (distance == Infinity) { console.log("NA"); } else { console.log(bestElement + " " + distance); } i++; } } function dist(from, to){ return fabs((from >> 11) - (to >> 11)) + fabs((from & 2047) - (to & 2047)); } function min(a1, a2){ return a1 > a2 ? a2 : a1; } function pos(a, b){ // 2^10 = 1024なので、下位10ビットでy座標を、上位ビットでx座標を表す return (a << 11) + b; } function fabs(a){ return (a ^ (a >> 31)) - (a >> 31); } var input = ''; process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function(chunk) { input += chunk; }); process.stdin.on('end', function() { input = input.split('\n'); main(); });
Main.java:1: error: unnamed classes are a preview feature and are disabled by default. function main(){ ^ (use --enable-preview to enable unnamed classes) Main.java:15: error: illegal start of expression var elem = [[],[],[],[],[]]; ^ Main.java:48: error: illegal start of expression var dp = [[],[],[],[],[]]; ^ Main.java:112: error: <identifier> expected function dist(from, to){ ^ Main.java:112: error: <identifier> expected function dist(from, to){ ^ Main.java:116: error: <identifier> expected function min(a1, a2){ ^ Main.java:116: error: <identifier> expected function min(a1, a2){ ^ Main.java:120: error: <identifier> expected function pos(a, b){ ^ Main.java:120: error: <identifier> expected function pos(a, b){ ^ Main.java:125: error: <identifier> expected function fabs(a){ ^ Main.java:130: error: empty character literal input = ''; ^ Main.java:132: error: class, interface, enum, or record expected process.stdin.resume(); ^ Main.java:133: error: class, interface, enum, or record expected process.stdin.setEncoding('utf8'); ^ Main.java:133: error: unclosed character literal process.stdin.setEncoding('utf8'); ^ Main.java:133: error: unclosed character literal process.stdin.setEncoding('utf8'); ^ Main.java:134: error: class, interface, enum, or record expected process.stdin.on('data', function(chunk) { ^ Main.java:134: error: unclosed character literal process.stdin.on('data', function(chunk) { ^ Main.java:134: error: unclosed character literal process.stdin.on('data', function(chunk) { ^ Main.java:136: error: class, interface, enum, or record expected }); ^ Main.java:137: error: class, interface, enum, or record expected process.stdin.on('end', function() { ^ Main.java:137: error: unclosed character literal process.stdin.on('end', function() { ^ Main.java:137: error: unclosed character literal process.stdin.on('end', function() { ^ Main.java:139: error: class, interface, enum, or record expected main(); ^ Main.java:140: error: class, interface, enum, or record expected }); ^ 24 errors
s837360121
p00215
Java
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { // 読み込んでフィールドを作る Scanner sc = new Scanner(System.in); while (true) { int x = sc.nextInt(); int y = sc.nextInt(); if (x == 0 && y == 0) { break; } Pachimon pachimon = new Pachimon(); for (int fy = 0; fy < y; fy++) { String in = sc.next(); for (int fx = 0; fx < x; fx++) { char c = in.charAt(fx); switch (c) { case 'S': pachimon.setStart(new Pos(fx, fy)); break; case 'G': pachimon.setGoal(new Pos(fx, fy)); break; case '.': break; default: pachimon.addPachimon(Character.getNumericValue(c) - 1, new Pos(fx, fy)); break; } } } pachimon.search(); } } /** 場所 */ private static class Pos { public int x; public int y; public Pos(int x, int y) { this.x = x; this.y = y; } } private static class Pachimon { private List<List<Pos>> pachimon = new ArrayList<List<Pos>>(); private Pos s; private Pos g; private static int INF = Integer.MAX_VALUE; public Pachimon() { for (int i = 0; i < 5; i++) { this.pachimon.add(new ArrayList<Pos>()); } } public void setStart(Pos s) { this.s = s; } public void setGoal(Pos g) { this.g = g; } public void addPachimon(int elem, Pos pos) { this.pachimon.get(elem).add(pos); } public void search() { int start = -1; int dist = INF; // 属性ごとにループ for (int i = 0; i < 5; i++) { // DPの初期化 DP[属性][同じ属性内の連番] int[][] dp = new int[5][1000]; for (int h = 0; h < 5; h++) { Arrays.fill(dp[h], INF); } // 最初に選んだパチモンから次に捕まえられる属性番号 int first = (i + 1) % 5; for (int j = 0; j < this.pachimon.get(first).size(); j++) { // s→e1を計算 dp[first][j] = dist(this.s, this.pachimon.get(first).get(j)); } // s->1->2->3->4->g // なので、ループは間の-> * 3分まわす for (int e = 0; e < 3; e++) { // ex->e(x+1) int now = (first + e) % 5; int next = (now + 1) % 5; for (int j = 0; j < this.pachimon.get(now).size(); j++) { for (int k = 0; k < this.pachimon.get(next).size(); k++) { dp[next][k] = min( dp[next][k], add(dp[now][j], dist(this.pachimon.get(now).get(j), this.pachimon.get(next) .get(k)))); } } } int last = (first + 3) % 5; for (int j = 0; j < this.pachimon.get(last).size(); j++) { // e4->g int d = add(dp[last][j], dist(this.pachimon.get(last).get(j), this.g)); if (d < dist) { dist = d; start = i + 1; } } } if (dist == INF) { System.out.println("NA"); } else { System.out.println(start + " " + dist); } } private int dist(Pos from, Pos to) { return abs(from.x - to.x) + abs(from.y - to.y); } private int add(int x, int y) { if (x == INF || y == INF) { return INF; } return x + y; } private int min(int x, int y){ int t = (x - y); return y + (t & (t >> 31)); } private int abs(int x){ int mask = a >> 31; return (x ^ mask) - mask; } } }
Main.java:166: error: cannot find symbol int mask = a >> 31; ^ symbol: variable a location: class Pachimon 1 error
s102095548
p00215
Java
import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { // 読み込んでフィールドを作る Scanner sc = new Scanner(System.in); while (true) { int x = sc.nextInt(); int y = sc.nextInt(); if (x == 0 && y == 0) { break; } Pachimon pachimon = new Pachimon(); for (int fy = 0; fy < y; fy++) { String in = sc.next(); for (int fx = 0; fx < x; fx++) { char c = in.charAt(fx); switch (c) { case 'S': pachimon.setStart(new Pos(fx, fy)); break; case 'G': pachimon.setGoal(new Pos(fx, fy)); break; case '.': break; default: pachimon.addPachimon(Character.getNumericValue(c) - 1, new Pos(fx, fy)); break; } } } pachimon.search(); } } /** 場所 */ private static class Pos { public int x; public int y; public Pos(int x, int y) { this.x = x; this.y = y; } } private static class Pachimon { private List<List<Pos>> pachimon = new ArrayList<List<Pos>>(); private Pos s; private Pos g; private static int INF = 1<<30; public Pachimon() { for (int i = 0; i < 5; i++) { this.pachimon.add(new ArrayList<Pos>()); } } public void setStart(Pos s) { this.s = s; } public void setGoal(Pos g) { this.g = g; } public void addPachimon(int elem, Pos pos) { this.pachimon.get(elem).add(pos); } public void search() { int start = -1; int dist = INF; // 属性ごとにループ for (int i = 0; i < 5; i++) { // DPの初期化 DP[属性][同じ属性内の連番] int[][] dp = new int[5][1000]; for (int h = 0; h < 5; h++) { Arrays.fill(dp[h], INF); } // 最初に選んだパチモンから次に捕まえられる属性番号 int first = (i + 1) % 5; for (int j = 0; j < this.pachimon.get(first).size(); j++) { // s→e1を計算 dp[first][j] = dist(this.s, this.pachimon.get(first).get(j)); } // s->1->2->3->4->g // なので、ループは間の-> * 3分まわす for (int e = 0; e < 3; e++) { // ex->e(x+1) int now = (first + e) % 5; int next = (now + 1) % 5; for (int j = 0; j < this.pachimon.get(now).size(); j++) { for (int k = 0; k < this.pachimon.get(next).size(); k++) { dp[next][k] = min( dp[next][k], add(dp[now][j], dist(this.pachimon.get(now).get(j), this.pachimon.get(next) .get(k)))); } } } int last = (first + 3) % 5; for (int j = 0; j < this.pachimon.get(last).size(); j++) { // e4->g int d = add(dp[last][j], dist(this.pachimon.get(last).get(j), this.g)); if (d < dist) { dist = d; start = i + 1; } } } if (dist == INF) { System.out.println("NA"); } else { System.out.println(start + " " + dist); } } private int dist(Pos from, Pos to) { return abs(from.x - to.x) + abs(from.y - to.y); } private int add(int x, int y) { if (x == INF || y == INF) { return INF; } return x + y; } private int min(int x, int y){ int t = (x - y); return y + (t & (t >> 31)); } private int abs(int x){ int mask = a >> 31; return (x ^ mask) - mask; } } }
Main.java:166: error: cannot find symbol int mask = a >> 31; ^ symbol: variable a location: class Pachimon 1 error
s216370736
p00215
Java
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.List; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Comparator; public class Main { public static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static final Point start = new Point(); public static final Point goal = new Point(); public static final PriorityQueue<Point> q = new PriorityQueue<Point>(); public static final List<List<Point> > pointListByType = new List<List<Point> >(); static { for(int i = 0; i < 5; i++) { pointListByType.add(new ArrayList<Point>()); } } public static void main(String args[]) throws IOException { while(true) { final String mapSizeStr = br.readLine(); if("0 0".equals(mapSizeStr)) break; final String[] splittedStr = mapSizeStr.split(" "); final int x = Integer.parseInt(splittedStr[0]); final int y = Integer.parseInt(splittedStr[1]); for(int i = 0; i < 5; i++) { pointListByType.get(i).clear(); } Point.nextId = 0; for(int r = 0; r < y; r++){ final String line = br.readLine(); final char[] caray = line.toCharArray(); for(int c = 0; c < x; c++) { char pointLiteral = caray[c]; switch(pointLiteral) { case '.': //Do Nothing break; case 'S': start.init(c, r, -1); start.distanceFromStart = 0; break; case 'G': goal.init(c, r, -1); break; default: final int type = (int)pointLiteral - (int)'1'; pointListByType.get(type).add(new Point(c, r, type)); } } } int minLenType = -1; int minLen = Integer.MAX_VALUE; for (int firstType = 0; firstType < 5; firstType++) { final int shortestPathLen = searchShortestPath(firstType, minLen); if(minLen > shortestPathLen) { minLen = shortestPathLen; minLenType = firstType; } if(firstType == 4) break; for(int i = 0; i < 5; i++) { if(i == firstType) continue; final List<Point> tempPointList = pointListByType.get(i); final int pointListSize = tempPointList.size(); for(int j = 0; j < pointListSize; j++) { tempPointList.get(j).distanceFromStart = Integer.MAX_VALUE; } } goal.distanceFromStart = Integer.MAX_VALUE; } if(minLen == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println((minLenType + 1) + " " + minLen); } } } private static int searchShortestPath(final int firstType, final int minLen) { final int lastType = (firstType + 4) % 5; q.clear(); q.add(start); start.type = firstType; while(!q.isEmpty()) { final Point searchingPoint = q.poll(); final int searchingPointDistance = searchingPoint.distanceFromStart; if(searchingPointDistance >= minLen) return Integer.MAX_VALUE; if(searchingPoint.id == goal.id) return goal.distanceFromStart; if(searchingPoint.type == lastType) { final int distance = searchingPoint.distance(goal); if(goal.distanceFromStart > searchingPointDistance + distance) { goal.distanceFromStart = searchingPointDistance + distance; q.add(goal); } } else { final List<Point> nextPointList = pointListByType.get((searchingPoint.type + 1) % 5); final int nextPointListSize = nextPointList.size(); for(int i = 0; i < nextPointListSize; i++) { final Point tempNextPoint = nextPointList.get(i); final int distance = searchingPoint.distance(tempNextPoint); if(tempNextPoint.distanceFromStart > searchingPointDistance + distance) { tempNextPoint.distanceFromStart = searchingPointDistance + distance; q.add(tempNextPoint); } } } } return Integer.MAX_VALUE; } private static final class Point implements Comparable<Point>{ public static int nextId = 0; public int id; public int x; public int y; public int type; public int distanceFromStart; public Point() { this(-1, -1, -1); } public Point(final int x, final int y, final int type) { init(x, y, type); } public int distance(final Point p) { return abs(this.x - p.x) + abs(this.y - p.y); } public void init(final int x, final int y, final int type){ this.id = nextId++; this.x = x; this.y = y; this.type = type; this.distanceFromStart = Integer.MAX_VALUE; } @Override public int compareTo(final Point p) { return this.distanceFromStart - p.distanceFromStart; } private static int abs(final int n) { int mask = n >> 31; return (n ^ mask) - mask; } } }
Main.java:19: error: List is abstract; cannot be instantiated new List<List<Point> >(); ^ 1 error
s878266724
p00215
Java
+import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.List; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Comparator; class Point implements Comparable<Point>{ public static int nextId = 0; public int id; public int x; public int y; public int type; public int distanceFromStart; public Point() { this(-1, -1, -1); } public Point(int x, int y, int type) { init(x, y, type); } public int distance(final Point p) { return abs(this.x - p.x) + abs(this.y - p.y); } public void init(final int x, final int y, final int type){ this.id = nextId++; this.x = x; this.y = y; this.type = type; this.distanceFromStart = Integer.MAX_VALUE; } @Override public int compareTo(final Point p) { return this.distanceFromStart - p.distanceFromStart; } private static int abs(final int n) { int mask = n >> 31; return (n ^ mask) - mask; } } public class Main { public static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static final Point start = new Point(); public static final Point goal = new Point(); public static final PriorityQueue<Point> q = new PriorityQueue<Point>(); public static final List<Point> allPachiCrePointList = new ArrayList<Point>(); public static final List<List<Point> > pointListByType = new ArrayList<List<Point> >(); static { for(int i = 0; i < 5; i++) { pointListByType.add(new ArrayList<Point>()); } } public static void main(String args[]) throws IOException { while(true) { String[] splittedStr = br.readLine().split(" "); final int x = Integer.parseInt(splittedStr[0]); final int y = Integer.parseInt(splittedStr[1]); if(x + y == 0) break; for(int i = 0; i < 5; i++) { pointListByType.get(i).clear(); } Point.nextId = 0; for(int r = 0; r < y; r++){ final char[] caray = br.readLine().toCharArray(); for(int c = 0; c < x; c++) { char pointLiteral = caray[c]; if(pointLiteral == '.') { continue; } else if(pointLiteral == 'S') { start.init(c, r, -1); start.distanceFromStart = 0; } else if(pointLiteral == 'G') { goal.init(c, r, -1); } else { final int type = pointLiteral - '1'; pointListByType.get(type).add(new Point(c, r, type)); } } } int minLenType = -1; int minLen = Integer.MAX_VALUE; for (int firstType = 0; firstType < 5; firstType++) { final int shortestPathLen = searchShortestPath(firstType, minLen); if(minLen > shortestPathLen) { minLen = shortestPathLen; minLenType = firstType; } for(int i = 0; i < 5; i++) { final List<Point> tempPointList = pointListByType.get(i); for(int j = 0; j < tempPointList.size(); j++) { tempPointList.get(j).distanceFromStart = Integer.MAX_VALUE; } } goal.distanceFromStart = Integer.MAX_VALUE; } if(minLen == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println((minLenType + 1) + " " + minLen); } } } private static int searchShortestPath(int firstType, int minLen) { final int lastType = (firstType + 4) % 5; q.clear(); q.add(start); start.type = firstType; while(!q.isEmpty()) { final Point searchingPoint = q.poll(); if(searchingPoint.distanceFromStart >= minLen) return Integer.MAX_VALUE; if(searchingPoint.id == goal.id) return goal.distanceFromStart; if(searchingPoint.type != lastType) { List<Point> nextPointList = pointListByType.get((searchingPoint.type + 1) % 5); int nextPointListSize = nextPointList.size(); for(int i = 0; i < nextPointListSize; i++) { Point tempNextPoint = nextPointList.get(i); final int distance = searchingPoint.distance(tempNextPoint); final int searchinPointDistance = searchingPoint.distanceFromStart; final int tempDistance = searchinPointDistance + distance; if(tempNextPoint.distanceFromStart > tempDistance) { tempNextPoint.distanceFromStart = tempDistance; q.add(tempNextPoint); } } } else { final int distance = searchingPoint.distance(goal); final int searchinPointDistance = searchingPoint.distanceFromStart; if(goal.distanceFromStart > searchinPointDistance + distance) { goal.distanceFromStart = searchinPointDistance + distance; q.add(goal); } } } return Integer.MAX_VALUE; } }+
Main.java:1: error: class, interface, enum, or record expected +import java.io.BufferedReader; ^ Main.java:2: error: class, interface, enum, or record expected import java.io.InputStreamReader; ^ Main.java:3: error: class, interface, enum, or record expected import java.io.IOException; ^ Main.java:4: error: class, interface, enum, or record expected import java.util.List; ^ Main.java:5: error: class, interface, enum, or record expected import java.util.ArrayList; ^ Main.java:6: error: class, interface, enum, or record expected import java.util.PriorityQueue; ^ Main.java:7: error: class, interface, enum, or record expected import java.util.Comparator; ^ Main.java:165: error: class, interface, enum, or record expected }+ ^ 8 errors
s976153179
p00215
Java
+import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.List; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Comparator; class Point implements Comparable<Point>{ public static int nextId = 0; public int id; public int x; public int y; public int type; public int distanceFromStart; public Point() { this(-1, -1, -1); } public Point(int x, int y, int type) { init(x, y, type); } public int distance(final Point p) { return abs(this.x - p.x) + abs(this.y - p.y); } public void init(final int x, final int y, final int type){ this.id = nextId++; this.x = x; this.y = y; this.type = type; this.distanceFromStart = Integer.MAX_VALUE; } @Override public int compareTo(final Point p) { return this.distanceFromStart - p.distanceFromStart; } private static int abs(final int n) { int mask = n >> 31; return (n ^ mask) - mask; } } public class Main { public static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static final Point start = new Point(); public static final Point goal = new Point(); public static final PriorityQueue<Point> q = new PriorityQueue<Point>(); public static final List<Point> allPachiCrePointList = new ArrayList<Point>(); public static final List<List<Point> > pointListByType = new ArrayList<List<Point> >(); static { for(int i = 0; i < 5; i++) { pointListByType.add(new ArrayList<Point>()); } } public static void main(String args[]) throws IOException { while(true) { String[] splittedStr = br.readLine().split(" "); final int x = Integer.parseInt(splittedStr[0]); final int y = Integer.parseInt(splittedStr[1]); if(x + y == 0) break; for(int i = 0; i < 5; i++) { pointListByType.get(i).clear(); } Point.nextId = 0; for(int r = 0; r < y; r++){ final char[] caray = br.readLine().toCharArray(); for(int c = 0; c < x; c++) { char pointLiteral = caray[c]; if(pointLiteral == '.') { continue; } else if(pointLiteral == 'S') { start.init(c, r, -1); start.distanceFromStart = 0; } else if(pointLiteral == 'G') { goal.init(c, r, -1); } else { final int type = pointLiteral - '1'; pointListByType.get(type).add(new Point(c, r, type)); } } } int minLenType = -1; int minLen = Integer.MAX_VALUE; for (int firstType = 0; firstType < 5; firstType++) { final int shortestPathLen = searchShortestPath(firstType, minLen); if(minLen > shortestPathLen) { minLen = shortestPathLen; minLenType = firstType; } for(int i = 0; i < 5; i++) { final List<Point> tempPointList = pointListByType.get(i); for(int j = 0; j < tempPointList.size(); j++) { tempPointList.get(j).distanceFromStart = Integer.MAX_VALUE; } } goal.distanceFromStart = Integer.MAX_VALUE; } if(minLen == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println((minLenType + 1) + " " + minLen); } } } private static int searchShortestPath(int firstType, int minLen) { final int lastType = (firstType + 4) % 5; q.clear(); q.add(start); start.type = firstType; while(!q.isEmpty()) { final Point searchingPoint = q.poll(); if(searchingPoint.distanceFromStart >= minLen) return Integer.MAX_VALUE; if(searchingPoint.id == goal.id) return goal.distanceFromStart; if(searchingPoint.type != lastType) { List<Point> nextPointList = pointListByType.get((searchingPoint.type + 1) % 5); int nextPointListSize = nextPointList.size(); for(int i = 0; i < nextPointListSize; i++) { Point tempNextPoint = nextPointList.get(i); final int distance = searchingPoint.distance(tempNextPoint); final int searchinPointDistance = searchingPoint.distanceFromStart; final int tempDistance = searchinPointDistance + distance; if(tempNextPoint.distanceFromStart > tempDistance) { tempNextPoint.distanceFromStart = tempDistance; q.add(tempNextPoint); } } } else { final int distance = searchingPoint.distance(goal); final int searchinPointDistance = searchingPoint.distanceFromStart; if(goal.distanceFromStart > searchinPointDistance + distance) { goal.distanceFromStart = searchinPointDistance + distance; q.add(goal); } } } return Integer.MAX_VALUE; } }
Main.java:1: error: class, interface, enum, or record expected +import java.io.BufferedReader; ^ Main.java:2: error: class, interface, enum, or record expected import java.io.InputStreamReader; ^ Main.java:3: error: class, interface, enum, or record expected import java.io.IOException; ^ Main.java:4: error: class, interface, enum, or record expected import java.util.List; ^ Main.java:5: error: class, interface, enum, or record expected import java.util.ArrayList; ^ Main.java:6: error: class, interface, enum, or record expected import java.util.PriorityQueue; ^ Main.java:7: error: class, interface, enum, or record expected import java.util.Comparator; ^ 7 errors
s243085762
p00215
Java
import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Dijkstra { /** * @param args */ public static void main(String[] args) { } }
Main.java:10: error: class Dijkstra is public, should be declared in a file named Dijkstra.java public class Dijkstra { ^ 1 error
s382524440
p00215
Java
import java.awt.Point; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class Main { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ??????????????° */ static int maxNode = 0; /** ????????? */ static String[] map = new String[1000 * 1000]; /** ????????¢??????????????? */ static List<Point> pachimonList = new ArrayList<Point>(); /** * @param args */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { readMap(scanner); } } /** * ????????????????????????????????? * @param scanner ????????£?????? */ private static void readMap(Scanner scanner) { String[] mapSizeLine = scanner.nextLine().split(WHITE_SPACE); if (mapSizeLine.length < 2) { return; } // ??????????????±???????????? pachimonList.removeAll(pachimonList); maxNode = 0; // mapSizeX = Integer.parseInt(mapSizeLine[0]); // mapSizeY = Integer.parseInt(mapSizeLine[1]); // initializeMap(mapSizeX, mapSizeY); boolean startFlg = false; boolean goalFlg = false; while (scanner.hasNextLine()) { for (int i = 0; i < mapSizeY; i++) { String mapInfoLine = scanner.nextLine(); mapInfoLine = mapInfoLine.replaceAll(".", "9"); mapInfoLine = mapInfoLine.replaceAll("S", "0"); mapInfoLine = mapInfoLine.replaceAll("G", "6"); for (int j = 0; j < mapSizeX; j++) { int val = Integer.valueOf(mapInfoLine.charAt(j)); if (val < 9) { maxNode++; // ??????????????°??????????´¢ if (!startFlg) { if (val == 0) { pachimonList.add(createPos(0, calcIndex(j, i))); startFlg = true; break; } } // ??´????????°??????????´¢ if (!goalFlg) { if (val == 6) { pachimonList.add(createPos(6, calcIndex(j, i))); goalFlg = true; break; } } // ???????????¢????????°????¨???? pachimonList.add(createPos(Integer.valueOf(val), calcIndex(j, i))); } } } } Collections.sort(pachimonList, new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { return o1.x - o2.x; } }); } /** * ??????????????¨??????????´???????????????§????????? */ private static void initializeMap(int sizeX, int sizeY) { for (int i = 0; i < sizeX * sizeY; i++) { map[i] = ""; } } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } } import java.awt.Point; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class Main { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ??????????????° */ static int maxNode = 0; /** ????????? */ static String[] map = new String[1000 * 1000]; /** ????????¢??????????????? */ static List<Point> pachimonList = new ArrayList<Point>(); /** * @param args */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { readMap(scanner); } } /** * ????????????????????????????????? * @param scanner ????????£?????? */ private static void readMap(Scanner scanner) { String[] mapSizeLine = scanner.nextLine().split(WHITE_SPACE); if (mapSizeLine.length < 2) { return; } // ??????????????±???????????? pachimonList.removeAll(pachimonList); maxNode = 0; // mapSizeX = Integer.parseInt(mapSizeLine[0]); // mapSizeY = Integer.parseInt(mapSizeLine[1]); // initializeMap(mapSizeX, mapSizeY); boolean startFlg = false; boolean goalFlg = false; while (scanner.hasNextLine()) { for (int i = 0; i < mapSizeY; i++) { String mapInfoLine = scanner.nextLine(); mapInfoLine = mapInfoLine.replaceAll(".", "9"); mapInfoLine = mapInfoLine.replaceAll("S", "0"); mapInfoLine = mapInfoLine.replaceAll("G", "6"); for (int j = 0; j < mapSizeX; j++) { int val = Integer.valueOf(mapInfoLine.charAt(j)); if (val < 9) { maxNode++; // ??????????????°??????????´¢ if (!startFlg) { if (val == 0) { pachimonList.add(createPos(0, calcIndex(j, i))); startFlg = true; break; } } // ??´????????°??????????´¢ if (!goalFlg) { if (val == 6) { pachimonList.add(createPos(6, calcIndex(j, i))); goalFlg = true; break; } } // ???????????¢????????°????¨???? pachimonList.add(createPos(Integer.valueOf(val), calcIndex(j, i))); } } } } Collections.sort(pachimonList, new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { return o1.x - o2.x; } }); } /** * ??????????????¨??????????´???????????????§????????? */ private static void initializeMap(int sizeX, int sizeY) { for (int i = 0; i < sizeX * sizeY; i++) { map[i] = ""; } } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } }
Main.java:131: error: class, interface, enum, or record expected import java.awt.Point; ^ Main.java:132: error: class, interface, enum, or record expected import java.util.ArrayList; ^ Main.java:133: error: class, interface, enum, or record expected import java.util.Collections; ^ Main.java:134: error: class, interface, enum, or record expected import java.util.Comparator; ^ Main.java:135: error: class, interface, enum, or record expected import java.util.List; ^ Main.java:136: error: class, interface, enum, or record expected import java.util.Scanner; ^ 6 errors
s333579619
p00215
Java
import java.awt.Point; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class Pachimon { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ????????? */ static String[] map = new String[1000 * 1000]; /** ??????????????° */ static int maxNode = 0; /** ????????¢??????????????? */ static List<Point> pachimonList = new ArrayList<Point>(); /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { readMap(scanner); int[] adjacent = createAdjacent(); Point output = createPos(0, Integer.MAX_VALUE); for (int type = 1; type <= 5; type++) { // ??????????????¶????????¢??????????????£??\???????????????????????¨??´???????????????????????±????¨???? adjacent = addStartGoal(adjacent, type); // ??????????????????????????¢??????????????????????????????????????????????´¢ int cost = searchRoute(adjacent, type); if (cost < output.y) { output.x = type; output.y = cost; } } // ??????????????? if (output.y == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println(output.x + WHITE_SPACE + output.y); } } } /** * ????????????????????????????????? * @param scanner ????????£?????? */ private static void readMap(Scanner scanner) { String[] mapSizeLine = scanner.nextLine().split(WHITE_SPACE); if (mapSizeLine.length < 2) { return; } // ??????????????±???????????? initializeMap(); pachimonList.removeAll(pachimonList); maxNode = 0; mapSizeX = Integer.parseInt(mapSizeLine[0]); mapSizeY = Integer.parseInt(mapSizeLine[1]); for (int i = 0; i < mapSizeY; i++) { String mapInfoLine = scanner.nextLine(); mapInfoLine = mapInfoLine.replaceAll("\\.", "9"); mapInfoLine = mapInfoLine.replaceAll("S", "0"); mapInfoLine = mapInfoLine.replaceAll("G", "6"); for (int j = 0; j < mapSizeX; j++) { int val = Integer.parseInt(String.valueOf(mapInfoLine.charAt(j))); if (val < 9) { // ???????????¢????????°????¨???? pachimonList.add(createPos(Integer.valueOf(val), calcIndex(j, i))); maxNode++; } } } Collections.sort(pachimonList, new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { return o1.x - o2.x; } }); } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * ??????????????¨??????????´???????????????§????????? */ private static void initializeMap() { for (int i = 0; i < 1000000; i++) { map[i] = ""; } } /** * ??¨???????????????????????£??\??????????±??????? * @return ??£??\?????? */ private static int[] createAdjacent() { int[] adjacent = new int[maxNode * maxNode]; for (int i = 1; i < pachimonList.size() - 1; i++) { if (pachimonList.get(i).x < 5) { for (int j = i + 1; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x - pachimonList.get(i).x > 2) break; if (pachimonList.get(j).x == pachimonList.get(i).x + 1) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } else { for (int j = 0; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x == pachimonList.get(i).x - 4) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } } return adjacent; } /** * ??????????????????????????¢????????????????????????????????????????±???§???????????¢??????????????????<br> * ?????????????????????????????¢?????????????????????????¨???? * @param adjacent ??£??\?????? * @param firstType ??????????????????????????¢???????±???§ * @return ??£??\?????? */ private static int[] addStartGoal(int[] adjacent, int firstType) { // ??????????????????????????¢????????????????¬??????????????????????????????¢?????¨??????????????£??\??????????¨???? int startRow = 0; int goalRow = maxNode - 1; // ??????????????????????????¢????????????????????????????????????1?¨?????????????????????????4?¨?????????????????????? int nextType = getNextType(firstType); int endType = getEndType(firstType); // ??????????????¨??´???????????±????????????????????? resetStartGoal(adjacent); for (int i = 0; i < pachimonList.size(); i++) { if (pachimonList.get(i).x == nextType) adjacent[startRow * maxNode + i] = clucCost(pachimonList.get(0), pachimonList.get(i)); if (pachimonList.get(i).x == endType) adjacent[i * maxNode + goalRow] = clucCost(pachimonList.get(i), pachimonList.get(maxNode - 1)); } return adjacent; } /** * ??????????????¨??´????????????????????????????????????????????? * @return ????????????????????£??\?????? */ private static void resetStartGoal(int[] adjacent) { int goalRow = maxNode; for (int i = 0; i < maxNode; i++) { adjacent[i] = 0; adjacent[goalRow * (i + 1) - 1] = 0; } } /** * ??????????????????????????¢???????????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getNextType(int firstType) { if (firstType > 4) { return 1; } return firstType + 1; } /** * ??????????????????????????¢?????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getEndType(int firstType) { if (firstType > 1) return firstType - 1; return 5; } /** * ??£??\??????????¨?????????????????????????????????´???????????§???<br> * ????????????????????????????±??????? * @param adjacent ??£??\?????? * @return ???????????????????????? */ private static int searchRoute(int[] adjacent, int firstType) { // ?????????????¨??????????????????????????´??????? boolean[] visited = new boolean[maxNode]; // ??????????????????????????? int[] cost = new int[maxNode]; // ??????????????°??? int start = 0; // ??´????????°??? int goal = maxNode - 1; for (int i = 0; i < maxNode; i++) { cost[i] = Integer.MAX_VALUE; visited[i] = false; } // ??????????????°????????§???????????????0 cost[start] = 0; while (true) { // ?¨?????????????????????????????????§?????????????????????????±??????? int node = minIndex(cost, visited); if (node < 0) { return cost[goal]; } // ??¢?´¢???????????????????????????????????°???????????? visited[node] = true; for (int j = 0; j < maxNode; j++) { if (adjacent[node * maxNode + j] > 0 && !visited[j] && pachimonList.get(node).x != firstType) { int nextNodeCost = cost[node] + adjacent[node * maxNode + j]; // ????????§????????¢??????????°????????????°???????????¢??¨???????¨???¶ if (nextNodeCost < cost[j]) { cost[j] = nextNodeCost; } } } } } /** * ?¨???????????????????????????????????????????????????????????????????????????????????±??????? * @param cost ??????????????????????????? * @param visited ?????????????¨??????????????????????????´??????? * @return ?????????????????? */ private static int minIndex(int[] cost, boolean[] visited) { int index = 0; for (; index < visited.length; index++) { if (!visited[index]) break; } if (index == visited.length) return -1; for (int i = index + 1; i < visited.length; i++) { if (!visited[i] && cost[i] < cost[index]) index = i; } return index; } /** * ????????????????????????????????´???????????§????????????????¨????????????? * @param sx ???????????????X??§?¨? * @param sy ???????????????Y??§?¨? * @param gx ??´?????????X??§?¨? * @param gy ??´?????????Y??§?¨? * @param nextType ?¬????????????????????????¢????±???§ */ private static int clucCost(Point from, Point to) { int fx = from.y / mapSizeY; int fy = from.y % mapSizeY; int tx = to.y / mapSizeY; int ty = to.y % mapSizeY; return Math.abs(tx - fx) + Math.abs(ty - fy); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } }
Main.java:9: error: class Pachimon is public, should be declared in a file named Pachimon.java public class Pachimon { ^ 1 error
s172706401
p00215
Java
import java.awt.Point; import java.util.Scanner; public class Dijkstra { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ??????????????° */ static int maxNode = 0; /** ????????? */ static String[] map = new String[1000 * 1000]; /** ????????¢??????????????? */ /** ????????? */ // static List<Point> pachimonList = new ArrayList<Point>(); static Point[] pachimonList = new Point[1000 * 1000]; /** * @param args */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { readMap(scanner); } } /** * ????????????????????????????????? * @param scanner ????????£?????? */ private static void readMap(Scanner scanner) { String[] mapSizeLine = scanner.nextLine().split(WHITE_SPACE); if (mapSizeLine.length < 2) { return; } // ??????????????±???????????? // pachimonList.removeAll(pachimonList); maxNode = 0; mapSizeX = Integer.parseInt(mapSizeLine[0]); mapSizeY = Integer.parseInt(mapSizeLine[1]); // initializeMap(mapSizeX, mapSizeY); while (scanner.hasNextLine()) { for (int i = 0; i < mapSizeY; i++) { String mapInfoLine = scanner.nextLine(); mapInfoLine = mapInfoLine.replaceAll(".", "9"); mapInfoLine = mapInfoLine.replaceAll("S", "0"); mapInfoLine = mapInfoLine.replaceAll("G", "6"); for (int j = 0; j < mapSizeX; j++) { int val = Integer.valueOf(mapInfoLine.charAt(j)); if (val < 9) { // ???????????¢????????°????¨???? pachimonList[maxNode] = createPos(Integer.valueOf(val), calcIndex(j, i)); maxNode++; } } } } // Collections.sort(pachimonList, new Comparator<Point>() { // @Override // public int compare(Point o1, Point o2) { // return o1.x - o2.x; // } // }); } /** * ??????????????¨??????????´???????????????§????????? */ private static void initializeMap(int sizeX, int sizeY) { for (int i = 0; i < sizeX * sizeY; i++) { map[i] = ""; } } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } }
Main.java:4: error: class Dijkstra is public, should be declared in a file named Dijkstra.java public class Dijkstra { ^ 1 error
s195404337
p00215
Java
import java.awt.Point; import java.util.Scanner; public class Main { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ??????????????° */ static int maxNode = 0; /** ????????? */ // static String[] map = new String[1000 * 1000]; /** ????????¢??????????????? */ /** ????????? */ // static List<Point> pachimonList = new ArrayList<Point>(); // static Point[] pachimonList = new Point[1000 * 1000]; /** * @param args */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { readMap(scanner); } } /** ????????? */ // static String[] map = new String[1000 * 1000]; /** ????????¢??????????????? */ /** ????????? */ // static List<Point> pachimonList = new ArrayList<Point>(); // static Point[] pachimonList = new Point[1000 * 1000]; /** * @param args */ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { readMap(scanner); } } /** * ????????????????????????????????? * @param scanner ????????£?????? */ private static void readMap(Scanner scanner) { String[] mapSizeLine = scanner.nextLine().split(WHITE_SPACE); if (mapSizeLine.length < 2) { return; } // ??????????????±???????????? // pachimonList.removeAll(pachimonList); maxNode = 0; // mapSizeX = Integer.parseInt(mapSizeLine[0]); // mapSizeY = Integer.parseInt(mapSizeLine[1]); // initializeMap(mapSizeX, mapSizeY); for (int i = 0; i < mapSizeY; i++) { String mapInfoLine = scanner.nextLine(); mapInfoLine = mapInfoLine.replaceAll(".", "9"); mapInfoLine = mapInfoLine.replaceAll("S", "0"); mapInfoLine = mapInfoLine.replaceAll("G", "6"); for (int j = 0; j < mapSizeX; j++) { // int val = Integer.valueOf(mapInfoLine.charAt(j)); // if (val < 9) { // // ???????????¢????????°????¨???? //// pachimonList[maxNode] = createPos(Integer.valueOf(val), calcIndex(j, i)); // maxNode++; // } } } // Collections.sort(pachimonList, new Comparator<Point>() { // @Override // public int compare(Point o1, Point o2) { // return o1.x - o2.x; // } // }); } // /** // * ??????????????¨??????????´???????????????§????????? // */ // private static void initializeMap(int sizeX, int sizeY) { // for (int i = 0; i < sizeX * sizeY; i++) { // map[i] = ""; // } // } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } }
Main.java:48: error: method main(String[]) is already defined in class Main public static void main(String[] args) { ^ 1 error
s433961692
p00215
Java
import java.awt.Point; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class Main { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ????????? */ static String[] map = new String[1000 * 1000]; /** ?????????????¨??????????????????????????´??????? */ static boolean[] visited = new boolean[1000 * 1000]; /** ??????????????????????????? */ static int[] cost = new int[1000 * 1000]; /** ??????????????° */ static int maxNode = 0; /** ????????¢??????????????? */ static List<Point> pachimonList = new ArrayList<Point>(); /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { readMap(scanner); // int[] adjacent = createAdjacent(); // Point output = createPos(0, Integer.MAX_VALUE); // for (int type = 1; type <= 5 && maxNode > 0; type++) { // // ??????????????¶????????¢??????????????£??\???????????????????????¨??´???????????????????????±????¨???? // adjacent = addStartGoal(adjacent, type); // // // ??????????????????????????¢??????????????????????????????????????????????´¢ // int cost = searchRoute(adjacent, type); // if (cost < output.y) { // output.x = type; // output.y = cost; // } // } // ??????????????? if (output.y == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println(output.x + WHITE_SPACE + output.y); } } } /** * ????????????????????????????????? * @param scanner ????????£?????? */ private static void readMap(Scanner scanner) { String[] mapSizeLine = scanner.nextLine().split(WHITE_SPACE); if (mapSizeLine.length < 2) { return; } // ??????????????±???????????? pachimonList.removeAll(pachimonList); maxNode = 0; mapSizeX = Integer.parseInt(mapSizeLine[0]); mapSizeY = Integer.parseInt(mapSizeLine[1]); initializeMap(mapSizeX, mapSizeY); for (int i = 0; i < mapSizeY; i++) { String mapInfoLine = scanner.nextLine(); mapInfoLine = mapInfoLine.replaceAll("\\.", "9"); mapInfoLine = mapInfoLine.replaceAll("S", "0"); mapInfoLine = mapInfoLine.replaceAll("G", "6"); for (int j = 0; j < mapSizeX; j++) { int val = Integer.parseInt(String.valueOf(mapInfoLine.charAt(j))); if (val < 9) { // ???????????¢????????°????¨???? pachimonList.add(createPos(Integer.valueOf(val), calcIndex(j, i))); maxNode++; } } } Collections.sort(pachimonList, new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { return o1.x - o2.x; } }); } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * ??????????????¨??????????´???????????????§????????? * @param sizeX ??????????????????_X * @param sizeY ??????????????????_Y */ private static void initializeMap(int sizeX, int sizeY) { for (int i = 0; i < sizeX * sizeY; i++) { map[i] = ""; } } /** * ??¨???????????????????????£??\??????????±??????? * @return ??£??\?????? */ private static int[] createAdjacent() { int[] adjacent = new int[maxNode * maxNode]; for (int i = 1; i < pachimonList.size() - 1; i++) { if (pachimonList.get(i).x < 5) { for (int j = i + 1; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x - pachimonList.get(i).x > 2) break; if (pachimonList.get(j).x == pachimonList.get(i).x + 1) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } else { for (int j = 0; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x == pachimonList.get(i).x - 4) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } } return adjacent; } /** * ??????????????????????????¢????????????????????????????????????????±???§???????????¢??????????????????<br> * ?????????????????????????????¢?????????????????????????¨???? * @param adjacent ??£??\?????? * @param firstType ??????????????????????????¢???????±???§ * @return ??£??\?????? */ private static int[] addStartGoal(int[] adjacent, int firstType) { // ??????????????????????????¢????????????????¬??????????????????????????????¢?????¨??????????????£??\??????????¨???? int startRow = 0; int goalRow = maxNode - 1; // ??????????????????????????¢????????????????????????????????????1?¨?????????????????????????4?¨?????????????????????? int nextType = getNextType(firstType); int endType = getEndType(firstType); // ??????????????¨??´???????????±????????????????????? resetStartGoal(adjacent); for (int i = 0; i < pachimonList.size(); i++) { if (pachimonList.get(i).x == nextType) adjacent[startRow * maxNode + i] = clucCost(pachimonList.get(0), pachimonList.get(i)); if (pachimonList.get(i).x == endType) adjacent[i * maxNode + goalRow] = clucCost(pachimonList.get(i), pachimonList.get(maxNode - 1)); } return adjacent; } /** * ??????????????¨??´????????????????????????????????????????????? * @return ????????????????????£??\?????? */ private static void resetStartGoal(int[] adjacent) { int goalRow = maxNode; for (int i = 0; i < maxNode; i++) { adjacent[i] = 0; adjacent[goalRow * (i + 1) - 1] = 0; } } /** * ??????????????????????????¢???????????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getNextType(int firstType) { if (firstType > 4) { return 1; } return firstType + 1; } /** * ??????????????????????????¢?????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getEndType(int firstType) { if (firstType > 1) return firstType - 1; return 5; } /** * ??£??\??????????¨?????????????????????????????????´???????????§???<br> * ????????????????????????????±??????? * @param adjacent ??£??\?????? * @return ???????????????????????? */ private static int searchRoute(int[] adjacent, int firstType) { for (int i = 0; i < maxNode; i++) { cost[i] = Integer.MAX_VALUE; visited[i] = false; } // ??????????????°????????§???????????????0 cost[0] = 0; while (true) { // ?¨?????????????????????????????????§?????????????????????????±??????? int node = minIndex(cost, visited); if (node < 0) { return cost[maxNode - 1]; } // ??¢?´¢???????????????????????????????????°???????????? visited[node] = true; for (int j = 0; j < maxNode; j++) { if (adjacent[node * maxNode + j] > 0 && !visited[j] && pachimonList.get(node).x != firstType) { int nextNodeCost = cost[node] + adjacent[node * maxNode + j]; // ????????§????????¢??????????°????????????°???????????¢??¨???????¨???¶ if (nextNodeCost < cost[j]) { cost[j] = nextNodeCost; } } } } } /** * ?¨???????????????????????????????????????????????????????????????????????????????????±??????? * @param cost ??????????????????????????? * @param visited ?????????????¨??????????????????????????´??????? * @return ?????????????????? */ private static int minIndex(int[] cost, boolean[] visited) { int index = 0; for (; index < maxNode; index++) { if (!visited[index]) break; } if (index == maxNode) return -1; for (int i = index + 1; i < maxNode; i++) { if (!visited[i] && cost[i] < cost[index]) index = i; } return index; } /** * ????????????????????????????????´???????????§????????????????¨????????????? * @param sx ???????????????X??§?¨? * @param sy ???????????????Y??§?¨? * @param gx ??´?????????X??§?¨? * @param gy ??´?????????Y??§?¨? * @param nextType ?¬????????????????????????¢????±???§ */ private static int clucCost(Point from, Point to) { int fx = from.y / mapSizeY; int fy = from.y % mapSizeY; int tx = to.y / mapSizeY; int ty = to.y % mapSizeY; return Math.abs(tx - fx) + Math.abs(ty - fy); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } }
Main.java:60: error: cannot find symbol if (output.y == Integer.MAX_VALUE) { ^ symbol: variable output location: class Main Main.java:63: error: cannot find symbol System.out.println(output.x + WHITE_SPACE + output.y); ^ symbol: variable output location: class Main Main.java:63: error: cannot find symbol System.out.println(output.x + WHITE_SPACE + output.y); ^ symbol: variable output location: class Main 3 errors
s211753740
p00215
Java
import java.awt.Point; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Pachimon { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ????????? */ static String[] map = new String[1000 * 1000]; /** ?????????????¨??????????????????????????´??????? */ static boolean[] visited = new boolean[1000 * 1000]; /** ??????????????????????????? */ static int[] cost = new int[1000 * 1000]; /** ??????????????° */ static int maxNode = 0; /** ????????¢??????????????? */ static List<Point> pachimonList = new ArrayList<Point>(); /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); while (true) { if (readMap(br) == -1) { break; } int[] adjacent = createAdjacent(); Point output = createPos(0, Integer.MAX_VALUE); for (int type = 1; type <= 5 && maxNode > 0; type++) { // ??????????????¶????????¢??????????????£??\???????????????????????¨??´???????????????????????±????¨???? adjacent = addStartGoal(adjacent, type); // ??????????????????????????¢??????????????????????????????????????????????´¢ int cost = searchRoute(adjacent, type); if (cost < output.y) { output.x = type; output.y = cost; } } // ??????????????? if (output.y == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println(output.x + WHITE_SPACE + output.y); } } } /** * ????????????????????????????????? * @param scanner ????????£?????? * @throws IOException */ private static int readMap(BufferedReader br) throws IOException { String[] mapSizeLine = br.readLine().split(WHITE_SPACE); if (mapSizeLine.length < 2) { return -1; } // ??????????????±???????????? pachimonList.removeAll(pachimonList); maxNode = 0; mapSizeX = Integer.parseInt(mapSizeLine[0]); mapSizeY = Integer.parseInt(mapSizeLine[1]); initializeMap(mapSizeX, mapSizeY); for (int i = 0; i < mapSizeY; i++) { String mapInfoLine = br.readLine(); if (mapInfoLine == null) { return -1; } mapInfoLine = mapInfoLine.replaceAll("\\.", "9"); mapInfoLine = mapInfoLine.replaceAll("S", "0"); mapInfoLine = mapInfoLine.replaceAll("G", "6"); for (int j = 0; j < mapSizeX; j++) { int val = Integer.parseInt(String.valueOf(mapInfoLine.charAt(j))); if (val < 9) { // ???????????¢????????°????¨???? pachimonList.add(createPos(Integer.valueOf(val), calcIndex(j, i))); maxNode++; } } } Collections.sort(pachimonList, new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { return o1.x - o2.x; } }); return 0; } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * ??????????????¨??????????´???????????????§????????? * @param sizeX ??????????????????_X * @param sizeY ??????????????????_Y */ private static void initializeMap(int sizeX, int sizeY) { for (int i = 0; i < sizeX * sizeY; i++) { map[i] = ""; } } /** * ??¨???????????????????????£??\??????????±??????? * @return ??£??\?????? */ private static int[] createAdjacent() { int[] adjacent = new int[maxNode * maxNode]; for (int i = 1; i < pachimonList.size() - 1; i++) { if (pachimonList.get(i).x < 5) { for (int j = i + 1; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x - pachimonList.get(i).x > 2) break; if (pachimonList.get(j).x == pachimonList.get(i).x + 1) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } else { for (int j = 0; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x == pachimonList.get(i).x - 4) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } } return adjacent; } /** * ??????????????????????????¢????????????????????????????????????????±???§???????????¢??????????????????<br> * ?????????????????????????????¢?????????????????????????¨???? * @param adjacent ??£??\?????? * @param firstType ??????????????????????????¢???????±???§ * @return ??£??\?????? */ private static int[] addStartGoal(int[] adjacent, int firstType) { // ??????????????????????????¢????????????????¬??????????????????????????????¢?????¨??????????????£??\??????????¨???? int startRow = 0; int goalRow = maxNode - 1; // ??????????????????????????¢????????????????????????????????????1?¨?????????????????????????4?¨?????????????????????? int nextType = getNextType(firstType); int endType = getEndType(firstType); // ??????????????¨??´???????????±????????????????????? resetStartGoal(adjacent); for (int i = 0; i < pachimonList.size(); i++) { if (pachimonList.get(i).x == nextType) adjacent[startRow * maxNode + i] = clucCost(pachimonList.get(0), pachimonList.get(i)); if (pachimonList.get(i).x == endType) adjacent[i * maxNode + goalRow] = clucCost(pachimonList.get(i), pachimonList.get(maxNode - 1)); } return adjacent; } /** * ??????????????¨??´????????????????????????????????????????????? * @return ????????????????????£??\?????? */ private static void resetStartGoal(int[] adjacent) { int goalRow = maxNode; for (int i = 0; i < maxNode; i++) { adjacent[i] = 0; adjacent[goalRow * (i + 1) - 1] = 0; } } /** * ??????????????????????????¢???????????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getNextType(int firstType) { if (firstType > 4) { return 1; } return firstType + 1; } /** * ??????????????????????????¢?????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getEndType(int firstType) { if (firstType > 1) return firstType - 1; return 5; } /** * ??£??\??????????¨?????????????????????????????????´???????????§???<br> * ????????????????????????????±??????? * @param adjacent ??£??\?????? * @return ???????????????????????? */ private static int searchRoute(int[] adjacent, int firstType) { for (int i = 0; i < maxNode; i++) { cost[i] = Integer.MAX_VALUE; visited[i] = false; } // ??????????????°????????§???????????????0 cost[0] = 0; while (true) { // ?¨?????????????????????????????????§?????????????????????????±??????? int node = minIndex(cost, visited); if (node < 0) { return cost[maxNode - 1]; } // ??¢?´¢???????????????????????????????????°???????????? visited[node] = true; for (int j = 0; j < maxNode; j++) { if (adjacent[node * maxNode + j] > 0 && !visited[j] && pachimonList.get(node).x != firstType) { int nextNodeCost = cost[node] + adjacent[node * maxNode + j]; // ????????§????????¢??????????°????????????°???????????¢??¨???????¨???¶ if (nextNodeCost < cost[j]) { cost[j] = nextNodeCost; } } } } } /** * ?¨???????????????????????????????????????????????????????????????????????????????????±??????? * @param cost ??????????????????????????? * @param visited ?????????????¨??????????????????????????´??????? * @return ?????????????????? */ private static int minIndex(int[] cost, boolean[] visited) { int index = 0; for (; index < maxNode; index++) { if (!visited[index]) break; } if (index == maxNode) return -1; for (int i = index + 1; i < maxNode; i++) { if (!visited[i] && cost[i] < cost[index]) index = i; } return index; } /** * ????????????????????????????????´???????????§????????????????¨????????????? * @param sx ???????????????X??§?¨? * @param sy ???????????????Y??§?¨? * @param gx ??´?????????X??§?¨? * @param gy ??´?????????Y??§?¨? * @param nextType ?¬????????????????????????¢????±???§ */ private static int clucCost(Point from, Point to) { int fx = from.y / mapSizeY; int fy = from.y % mapSizeY; int tx = to.y / mapSizeY; int ty = to.y % mapSizeY; return Math.abs(tx - fx) + Math.abs(ty - fy); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } }
Main.java:10: error: class Pachimon is public, should be declared in a file named Pachimon.java public class Pachimon { ^ 1 error
s750530200
p00215
Java
import java.awt.Point; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Pachimon { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ????????? */ static String[] map = new String[1000 * 1000]; /** ?????????????¨??????????????????????????´??????? */ static boolean[] visited = new boolean[1000 * 1000]; /** ??????????????????????????? */ static int[] cost = new int[1000 * 1000]; /** ??????????????° */ static int maxNode = 0; /** ????????¢??????????????? */ static List<Point> pachimonList = new ArrayList<Point>(); /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); while (true) { if (readMap(br) == -1) { break; } int[] adjacent = createAdjacent(); Point output = createPos(0, Integer.MAX_VALUE); for (int type = 1; type <= 5 && maxNode > 0; type++) { // ??????????????¶????????¢??????????????£??\???????????????????????¨??´???????????????????????±????¨???? adjacent = addStartGoal(adjacent, type); // ??????????????????????????¢??????????????????????????????????????????????´¢ int cost = searchRoute(adjacent, type); if (cost < output.y) { output.x = type; output.y = cost; } } // ??????????????? if (output.y == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println(output.x + WHITE_SPACE + output.y); } } } /** * ????????????????????????????????? * @param scanner ????????£?????? * @throws IOException */ private static int readMap(BufferedReader br) throws IOException { String[] mapSizeLine = br.readLine().split(WHITE_SPACE); if (mapSizeLine.length < 2) { return -1; } // ??????????????±???????????? pachimonList.removeAll(pachimonList); maxNode = 0; mapSizeX = Integer.parseInt(mapSizeLine[0]); mapSizeY = Integer.parseInt(mapSizeLine[1]); initializeMap(mapSizeX, mapSizeY); for (int i = 0; i < mapSizeY; i++) { String mapInfoLine = br.readLine(); if (mapInfoLine == null) { return -1; } mapInfoLine = mapInfoLine.replaceAll("\\.", "9"); mapInfoLine = mapInfoLine.replaceAll("S", "0"); mapInfoLine = mapInfoLine.replaceAll("G", "6"); for (int j = 0; j < mapSizeX; j++) { int val = Integer.parseInt(String.valueOf(mapInfoLine.charAt(j))); if (val < 9) { // ???????????¢????????°????¨???? pachimonList.add(createPos(Integer.valueOf(val), calcIndex(j, i))); maxNode++; } } } Collections.sort(pachimonList, new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { return o1.x - o2.x; } }); return 0; } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * ??????????????¨??????????´???????????????§????????? * @param sizeX ??????????????????_X * @param sizeY ??????????????????_Y */ private static void initializeMap(int sizeX, int sizeY) { for (int i = 0; i < sizeX * sizeY; i++) { map[i] = ""; } } /** * ??¨???????????????????????£??\??????????±??????? * @return ??£??\?????? */ private static int[] createAdjacent() { int[] adjacent = new int[maxNode * maxNode]; for (int i = 1; i < pachimonList.size() - 1; i++) { if (pachimonList.get(i).x < 5) { for (int j = i + 1; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x - pachimonList.get(i).x > 2) break; if (pachimonList.get(j).x == pachimonList.get(i).x + 1) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } else { for (int j = 0; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x == pachimonList.get(i).x - 4) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } } return adjacent; } /** * ??????????????????????????¢????????????????????????????????????????±???§???????????¢??????????????????<br> * ?????????????????????????????¢?????????????????????????¨???? * @param adjacent ??£??\?????? * @param firstType ??????????????????????????¢???????±???§ * @return ??£??\?????? */ private static int[] addStartGoal(int[] adjacent, int firstType) { // ??????????????????????????¢????????????????¬??????????????????????????????¢?????¨??????????????£??\??????????¨???? int startRow = 0; int goalRow = maxNode - 1; // ??????????????????????????¢????????????????????????????????????1?¨?????????????????????????4?¨?????????????????????? int nextType = getNextType(firstType); int endType = getEndType(firstType); // ??????????????¨??´???????????±????????????????????? resetStartGoal(adjacent); for (int i = 0; i < pachimonList.size(); i++) { if (pachimonList.get(i).x == nextType) adjacent[startRow * maxNode + i] = clucCost(pachimonList.get(0), pachimonList.get(i)); if (pachimonList.get(i).x == endType) adjacent[i * maxNode + goalRow] = clucCost(pachimonList.get(i), pachimonList.get(maxNode - 1)); } return adjacent; } /** * ??????????????¨??´????????????????????????????????????????????? * @return ????????????????????£??\?????? */ private static void resetStartGoal(int[] adjacent) { int goalRow = maxNode; for (int i = 0; i < maxNode; i++) { adjacent[i] = 0; adjacent[goalRow * (i + 1) - 1] = 0; } } /** * ??????????????????????????¢???????????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getNextType(int firstType) { if (firstType > 4) { return 1; } return firstType + 1; } /** * ??????????????????????????¢?????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getEndType(int firstType) { if (firstType > 1) return firstType - 1; return 5; } /** * ??£??\??????????¨?????????????????????????????????´???????????§???<br> * ????????????????????????????±??????? * @param adjacent ??£??\?????? * @return ???????????????????????? */ private static int searchRoute(int[] adjacent, int firstType) { // ????????????6???????????´???????????¨??????????????¢???????????????????????¨?????§????????????????§£?????? if (maxNode < 6) return Integer.MAX_VALUE; for (int i = 0; i < maxNode; i++) { cost[i] = Integer.MAX_VALUE; visited[i] = false; } // ??????????????°????????§???????????????0 cost[0] = 0; while (true) { // ?¨?????????????????????????????????§?????????????????????????±??????? int node = minIndex(cost, visited); if (node < 0) { return cost[maxNode - 1]; } // ??¢?´¢???????????????????????????????????°???????????? visited[node] = true; for (int j = 0; j < maxNode; j++) { if (adjacent[node * maxNode + j] > 0 && !visited[j] && pachimonList.get(node).x != firstType) { int nextNodeCost = cost[node] + adjacent[node * maxNode + j]; // ????????§????????¢??????????°????????????°???????????¢??¨???????¨???¶ if (nextNodeCost < cost[j]) { cost[j] = nextNodeCost; } } } } } /** * ?¨???????????????????????????????????????????????????????????????????????????????????±??????? * @param cost ??????????????????????????? * @param visited ?????????????¨??????????????????????????´??????? * @return ?????????????????? */ private static int minIndex(int[] cost, boolean[] visited) { int index = 0; for (; index < maxNode; index++) { if (!visited[index]) break; } if (index == maxNode) return -1; for (int i = index + 1; i < maxNode; i++) { if (!visited[i] && cost[i] < cost[index]) index = i; } return index; } /** * ????????????????????????????????´???????????§????????????????¨????????????? * @param sx ???????????????X??§?¨? * @param sy ???????????????Y??§?¨? * @param gx ??´?????????X??§?¨? * @param gy ??´?????????Y??§?¨? * @param nextType ?¬????????????????????????¢????±???§ */ private static int clucCost(Point from, Point to) { int fx = from.y / mapSizeY; int fy = from.y % mapSizeY; int tx = to.y / mapSizeY; int ty = to.y % mapSizeY; return Math.abs(tx - fx) + Math.abs(ty - fy); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } }
Main.java:10: error: class Pachimon is public, should be declared in a file named Pachimon.java public class Pachimon { ^ 1 error
s584698996
p00215
Java
import java.awt.Point; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class Main { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ????????? */ static String[] map = new String[1000 * 1000]; /** ?????????????¨??????????????????????????´??????? */ static boolean[] visited = new boolean[1000 * 1000]; /** ??????????????????????????? */ static int[] cost = new int[1000 * 1000]; /** ??????????????° */ static int maxNode = 0; /** ????????¢??????????????? */ static List<Point> pachimonList = new ArrayList<Point>(); /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); String input = br.readLine(); while (scanner.hasNextLine()) { readMap(scanner); int[] adjacent = createAdjacent(); Point output = createPos(0, Integer.MAX_VALUE); for (int type = 1; type <= 5 && maxNode > 0; type++) { // ??????????????¶????????¢??????????????£??\???????????????????????¨??´???????????????????????±????¨???? adjacent = addStartGoal(adjacent, type); // ??????????????????????????¢??????????????????????????????????????????????´¢ int cost = searchRoute(adjacent, type); if (cost < output.y) { output.x = type; output.y = cost; } } // ??????????????? if (output.y == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println(output.x + WHITE_SPACE + output.y); } } } /** * ????????????????????????????????? * @param scanner ????????£?????? */ private static void readMap(Scanner scanner) { String[] mapSizeLine = scanner.nextLine().split(WHITE_SPACE); if (mapSizeLine.length < 2) { return; } // ??????????????±???????????? pachimonList.removeAll(pachimonList); maxNode = 0; mapSizeX = Integer.parseInt(mapSizeLine[0]); mapSizeY = Integer.parseInt(mapSizeLine[1]); initializeMap(mapSizeX, mapSizeY); for (int i = 0; i < mapSizeY; i++) { String mapInfoLine = scanner.nextLine(); mapInfoLine = mapInfoLine.replaceAll("\\.", "9"); mapInfoLine = mapInfoLine.replaceAll("S", "0"); mapInfoLine = mapInfoLine.replaceAll("G", "6"); for (int j = 0; j < mapSizeX; j++) { int val = Integer.parseInt(String.valueOf(mapInfoLine.charAt(j))); if (val < 9) { // ???????????¢????????°????¨???? pachimonList.add(createPos(Integer.valueOf(val), calcIndex(j, i))); maxNode++; } } } Collections.sort(pachimonList, new Comparator<Point>() { @Override public int compare(Point o1, Point o2) { return o1.x - o2.x; } }); } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * ??????????????¨??????????´???????????????§????????? * @param sizeX ??????????????????_X * @param sizeY ??????????????????_Y */ private static void initializeMap(int sizeX, int sizeY) { for (int i = 0; i < sizeX * sizeY; i++) { map[i] = ""; } } /** * ??¨???????????????????????£??\??????????±??????? * @return ??£??\?????? */ private static int[] createAdjacent() { int[] adjacent = new int[maxNode * maxNode]; for (int i = 1; i < pachimonList.size() - 1; i++) { if (pachimonList.get(i).x < 5) { for (int j = i + 1; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x - pachimonList.get(i).x > 2) break; if (pachimonList.get(j).x == pachimonList.get(i).x + 1) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } else { for (int j = 0; j < pachimonList.size() - 1; j++) { if (pachimonList.get(j).x == pachimonList.get(i).x - 4) adjacent[i * maxNode + j] = clucCost(pachimonList.get(i), pachimonList.get(j)); } } } return adjacent; } /** * ??????????????????????????¢????????????????????????????????????????±???§???????????¢??????????????????<br> * ?????????????????????????????¢?????????????????????????¨???? * @param adjacent ??£??\?????? * @param firstType ??????????????????????????¢???????±???§ * @return ??£??\?????? */ private static int[] addStartGoal(int[] adjacent, int firstType) { // ??????????????????????????¢????????????????¬??????????????????????????????¢?????¨??????????????£??\??????????¨???? int startRow = 0; int goalRow = maxNode - 1; // ??????????????????????????¢????????????????????????????????????1?¨?????????????????????????4?¨?????????????????????? int nextType = getNextType(firstType); int endType = getEndType(firstType); // ??????????????¨??´???????????±????????????????????? resetStartGoal(adjacent); for (int i = 0; i < pachimonList.size(); i++) { if (pachimonList.get(i).x == nextType) adjacent[startRow * maxNode + i] = clucCost(pachimonList.get(0), pachimonList.get(i)); if (pachimonList.get(i).x == endType) adjacent[i * maxNode + goalRow] = clucCost(pachimonList.get(i), pachimonList.get(maxNode - 1)); } return adjacent; } /** * ??????????????¨??´????????????????????????????????????????????? * @return ????????????????????£??\?????? */ private static void resetStartGoal(int[] adjacent) { int goalRow = maxNode; for (int i = 0; i < maxNode; i++) { adjacent[i] = 0; adjacent[goalRow * (i + 1) - 1] = 0; } } /** * ??????????????????????????¢???????????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getNextType(int firstType) { if (firstType > 4) { return 1; } return firstType + 1; } /** * ??????????????????????????¢?????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getEndType(int firstType) { if (firstType > 1) return firstType - 1; return 5; } /** * ??£??\??????????¨?????????????????????????????????´???????????§???<br> * ????????????????????????????±??????? * @param adjacent ??£??\?????? * @return ???????????????????????? */ private static int searchRoute(int[] adjacent, int firstType) { for (int i = 0; i < maxNode; i++) { cost[i] = Integer.MAX_VALUE; visited[i] = false; } // ??????????????°????????§???????????????0 cost[0] = 0; while (true) { // ?¨?????????????????????????????????§?????????????????????????±??????? int node = minIndex(cost, visited); if (node < 0) { return cost[maxNode - 1]; } // ??¢?´¢???????????????????????????????????°???????????? visited[node] = true; for (int j = 0; j < maxNode; j++) { if (adjacent[node * maxNode + j] > 0 && !visited[j] && pachimonList.get(node).x != firstType) { int nextNodeCost = cost[node] + adjacent[node * maxNode + j]; // ????????§????????¢??????????°????????????°???????????¢??¨???????¨???¶ if (nextNodeCost < cost[j]) { cost[j] = nextNodeCost; } } } } } /** * ?¨???????????????????????????????????????????????????????????????????????????????????±??????? * @param cost ??????????????????????????? * @param visited ?????????????¨??????????????????????????´??????? * @return ?????????????????? */ private static int minIndex(int[] cost, boolean[] visited) { int index = 0; for (; index < maxNode; index++) { if (!visited[index]) break; } if (index == maxNode) return -1; for (int i = index + 1; i < maxNode; i++) { if (!visited[i] && cost[i] < cost[index]) index = i; } return index; } /** * ????????????????????????????????´???????????§????????????????¨????????????? * @param sx ???????????????X??§?¨? * @param sy ???????????????Y??§?¨? * @param gx ??´?????????X??§?¨? * @param gy ??´?????????Y??§?¨? * @param nextType ?¬????????????????????????¢????±???§ */ private static int clucCost(Point from, Point to) { int fx = from.y / mapSizeY; int fy = from.y % mapSizeY; int tx = to.y / mapSizeY; int ty = to.y % mapSizeY; return Math.abs(tx - fx) + Math.abs(ty - fy); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } }
Main.java:43: error: cannot find symbol String input = br.readLine(); ^ symbol: variable br location: class Main 1 error
s972245828
p00215
Java
import java.awt.Point; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Pachimon { /** ????§??????? */ static final String WHITE_SPACE = " "; /** ??????????????????_X */ static int mapSizeX = 0; /** ??????????????????_Y */ static int mapSizeY = 0; /** ??????????????° */ static int maxNode = 0; /** ????????¢??????????????? */ static List<Point> pachimonList = new ArrayList<Point>(); /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { InputStreamReader is = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(is); while (true) { String[] mapSizeLine = br.readLine().split(WHITE_SPACE); mapSizeX = Integer.parseInt(mapSizeLine[0]); mapSizeY = Integer.parseInt(mapSizeLine[1]); if (mapSizeX == 0 && mapSizeY == 0) break; readMap(br); Point output = createPos(0, Integer.MAX_VALUE); if (maxNode > 5) { for (int type = 1; type <= 5; type++) { // ??????????????????????????¢??????????????????????????????????????????????´¢ int cost = searchRoute(type); if (cost < output.y && cost > 0) { output.x = type; output.y = cost; } } } // ??????????????? if (output.y == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println(output.x + WHITE_SPACE + output.y); } } } /** * ????????????????????????????????? * @param scanner ????????£?????? * @throws IOException */ private static void readMap(BufferedReader br) throws IOException { // ??????????????±???????????? pachimonList.removeAll(pachimonList); maxNode = 0; for (int i = 0; i < mapSizeY; i++) { for (int j = 0; j < mapSizeX; j++) { int val = convertInt(br.read()); if (val < 9) { // ???????????¢????????°????¨???? pachimonList.add(createPos(val, calcIndex(j, i))); } } // ????????????????£???°??? br.readLine(); } maxNode = pachimonList.size(); } /** * ??¢????????????????????????int?????????????????? * @param target ????±?????????? * @return ??????????????? */ private static int convertInt(int target) { if (target == 83) return 0; if (target == 71) return 6; if (target >= 49 && target <= 53) return target - 48; return 9; } /** * X????????????????????´?????????????????¢???????±???§????¨????<br> * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br> * Y????????????????????????????????????????´? * @param type ?????????????????´?????????????????¢???????±???§ * @param index ?????????????????????????????? * @return */ private static Point createPos(int type, int index) { return new Point(type, index); } /** * ?????¨????????¢???????????????????????????????????????????????¢???????±???§????????? * @param currentType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getNextType(int currentType) { if (currentType == 5) return 1; return currentType + 1; } /** * ??????????????????????????¢?????????????????????????????????????????¢???????±???§????????? * @param firstType ??????????????????????????¢???????±???§ * @return ?????????????????????????????¢???????±???§ */ private static int getEndType(int firstType) { if (firstType == 1) return 5; return firstType - 1; } /** * ??£??\??????????¨?????????????????????????????????´???????????§???<br> * ????????????????????????????±??????? * @param adjacent ??£??\?????? * @return ???????????????????????? */ private static int searchRoute(int firstType) { /** ?????????????¨??????????????????????????´??????? */ boolean[] visited = new boolean[maxNode]; /** ??????????????????????????? */ int[] cost = new int[maxNode]; for (int i = 0; i < maxNode; i++) { cost[i] = Integer.MAX_VALUE; visited[i] = false; } // ??????????????°????????§???????????????0 cost[0] = 0; while (true) { // ?¨?????????????????????????????????§?????????????????????????±??????? int node = minIndex(cost, visited); if (node < 0) { return cost[maxNode - 1]; } // ??¢?´¢???????????????????????????????????°???????????? visited[node] = true; for (int j = 0; j < maxNode; j++) { if (isLinked(node, j, firstType) && !visited[j]) { int nextNodeCost = cost[node] + clucCost(pachimonList.get(node), pachimonList.get(j)); // ????????§????????¢??????????°????????????°???????????¢??¨???????¨???¶ if (nextNodeCost < cost[j]) { cost[j] = nextNodeCost; } } } } } /** * ?????¨??????????????¨????±??????????????????\?¶?????????????????????????????????\ * @param node ?????¨???????????? * @param target ????±????????????? * @return ?????\?????? */ private static boolean isLinked(int node, int target, int firstType) { int currentType = pachimonList.get(node).x; int targetType = pachimonList.get(target).x; // ??????????????¢?????¨???????±???§?????????????????????????????????????????\?¶???????????????? if (currentType == firstType) return false; // ????±??????????????????¢?????¨???????±???§?????´????????\?¶???????????????? if (targetType == firstType) return false; // ??????????????´???????????´????????\?¶?????????????????????????????????? if (currentType == maxNode) return false; // ????????????????????????("0")?????´??????????±???????????????????????????¢???????±???§????¬?????????\?¶???????????????? if (currentType == 0) return targetType == getNextType(firstType); // ?????¨????????????????±???§????????????????????????????????¢????????´????????´??????????????\?¶? if (currentType == getEndType(firstType)) return targetType == 6; return getNextType(currentType) == targetType; } /** * ?¨???????????????????????????????????????????????????????????????????????????????????±??????? * @param cost ??????????????????????????? * @param visited ?????????????¨??????????????????????????´??????? * @return ?????????????????? */ private static int minIndex(int[] cost, boolean[] visited) { int index = 0; for (; index < maxNode; index++) { if (!visited[index]) break; } if (index == maxNode) return -1; for (int i = index + 1; i < maxNode; i++) { if (!visited[i] && cost[i] < cost[index]) index = i; } return index; } /** * ????????????????????????????????´???????????§????????????????¨????????????? * @param sx ???????????????X??§?¨? * @param sy ???????????????Y??§?¨? * @param gx ??´?????????X??§?¨? * @param gy ??´?????????Y??§?¨? * @param nextType ?¬????????????????????????¢????±???§ */ private static int clucCost(Point from, Point to) { int fx = from.y / mapSizeY; int fy = from.y % mapSizeY; int tx = to.y / mapSizeY; int ty = to.y % mapSizeY; return Math.abs(tx - fx) + Math.abs(ty - fy); } /** * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´????????? * * @param x X??§?¨? * @param y Y??§?¨? * @return */ private static int calcIndex(int x, int y) { return x * mapSizeY + y; } }
Main.java:8: error: class Pachimon is public, should be declared in a file named Pachimon.java public class Pachimon { ^ 1 error
s244965923
p00215
Java
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Scanner; public class PachimonCreature { public static void main(String... args) { for (List<String> mapStrings : getMapStringsList()) { if (mapStrings.isEmpty()) { break; } // マップの文字列をもとに全ての座標を生成する Coordinates coordinates = new Coordinates(mapStrings); // ゴールまでの最短経路を探索して出力する PachimonCreaturePlayer player = new PachimonCreaturePlayer(); player.completeGame(coordinates); player.output(); } } static class PachimonCreaturePlayer { private PachimonType firstType; // 最初に選ぶべきパチクリの属性 private int minCost; // 最小移動数 void completeGame(Coordinates coordinates) { // 捕まえるパチクリの属性の順番と、最初に選ぶパチクリの属性を生成する // (例:「火」⇒「氷」⇒「木」⇒「土」の順で捕まえる場合、順番の最後の属性「水」が最初に選ぶパチクリの属性となる) List<PachimonType> typeList = PachimonType.getPachimonTypeList(); LinkedList<PachimonType> orderToCatch = new LinkedList<PachimonType>(); for (PachimonType type : typeList) { orderToCatch.add(type); } // 最初に選ぶパチクリの属性5パターンすべてについて、 // 順番通りにパチクリを捕まえていったときの最小移動数を取得する for (int i = 0; i < 5; i++) { int cost = getMinCostWithPachimonType(coordinates, orderToCatch); if (i == 0 || (cost < this.minCost && 0 < cost)) { // 現在保持している最小移動数より小さい場合にはそちらで上書きする this.minCost = cost; this.firstType = orderToCatch.peekLast(); } // 捕まえる属性の順番を1つずらす PachimonType head = orderToCatch.poll(); orderToCatch.add(head); } } private int getMinCostWithPachimonType(Coordinates coordinates, List<PachimonType> orderToCatch) { // スタート位置の座標をルートノードとする Node startNode = new Field(coordinates.getStart(), 0, 0); // 属性ごとに全ての座標を取得し、スタート位置を頂点とする木構造を構築する // (レベル0・・・スタート位置の座標、レベル1・・・属性Aのパチクリの全座標、レベル2・・・属性Bのパチクリの全座標 ・・・) for (int i = 0; i < 4; i++) { List<Coordinate> coordinatesOfType = coordinates.getTypeList(orderToCatch.get(i)); if (coordinatesOfType.isEmpty()) { // 捕まえられるパチクリがいない場合 return 0; } for (Coordinate coordinate : coordinatesOfType) { startNode.add(coordinate, i + 1); } } // ゴール位置の座標をリーフとする startNode.add(coordinates.getGoal(), 5); // スタート(ルート)からゴール(リーフ)までの木構造を辿り、最小移動数を返す return startNode.getMinCostToGoal(); } void output() { if (this.minCost == 0) { System.out.println("NA"); } else { System.out.println(this.firstType.getValue() + " " + this.minCost); } } } /** * 移動経路を構成する木構造の各ノードを表現するクラス */ static abstract class Node { protected int level; // 木構造における本ノードのレベル protected int costFromStart; // スタート位置(ルート)からの移動数 protected Coordinate coordinate; // 本ノードのマップ上における座標 Node(Coordinate coordinate, int level, int costFromStart) { this.coordinate = coordinate; this.level = level; this.costFromStart = costFromStart; } void add(Coordinate coordinate, int level) { throw new UnsupportedOperationException(); } abstract int getMinCostToGoal(); } /** * ノードのうち、ゴール位置以外のノードを表現するクラス。子ノードを持つ。 */ static class Field extends Node { private List<Node> childNodes = new ArrayList<Node>(); // 子ノード Field(Coordinate coordinate, int level, int costFromStart) { super(coordinate, level, costFromStart); } void add(Coordinate coordinate, int level) { if (level - this.level == 1) { // 自分の直下レベルであれば自分の子ノードに追加する int cost = this.coordinate.calcCost(coordinate) + this.costFromStart; this.childNodes.add(coordinate.isGoal ? new Goal(coordinate, level, cost) : new Field(coordinate, level, cost)); return; } // それより下のレベルであれば全ての子ノードに処理を委譲 for (Node childNode : childNodes) { childNode.add(coordinate, level); } } @Override int getMinCostToGoal() { // 全ての子ノードを辿ってゴール(リーフ)までの移動数を取得し、そのうちの最小のものを返す List<Integer> list = new ArrayList<Integer>(); for (Node node : this.childNodes) { list.add(node.getMinCostToGoal()); } return Collections.min(list); } } /** * ノードのうち、ゴール位置を表現するクラス。子ノードを持たない。 */ static class Goal extends Node { Goal(Coordinate coordinates, int level, int costFromStart) { super(coordinates, level, costFromStart); } @Override int getMinCostToGoal() { return this.costFromStart; } } /** * 全ての座標を保持するクラス */ static class Coordinates { private Coordinate start; // スタートの座標 private Coordinate goal; // ゴールの座標 // 属性をキーとし、その属性のパチクリの位置座標リストを値として持つMap private Map<PachimonType, List<Coordinate>> pachimonCoordinatesMap = new HashMap<PachimonType, List<Coordinate>>(); Coordinates(List<String> lines) { // 全属性分の位置座標リストを用意してMapに格納する List<PachimonType> pachimonTypeList = PachimonType.getPachimonTypeList(); for (PachimonType type : pachimonTypeList) { this.pachimonCoordinatesMap.put(type, new ArrayList<Coordinate>()); } // マップを走査してスタート、ゴール、パチクリの全座標を取得して格納する int x = 0; for (String line : lines) { int y = 0; for (char c : line.toCharArray()) { String str = String.valueOf(c); if (str.equals("S")) { this.start = new Coordinate(x, y); } else if (str.equals("G")) { this.goal = new Coordinate(x, y, true); } else if (str.equals(".")) { // なにもしない } else { PachimonType type = PachimonType.valueOf(Integer.parseInt(str)); Coordinate coordinates = new Coordinate(x, y); this.pachimonCoordinatesMap.get(type).add(coordinates); } y++; } x++; } } Coordinate getStart() { return this.start; } Coordinate getGoal() { return this.goal; } List<Coordinate> getTypeList(PachimonType type) { // 指定された属性のパチクリの座標リストを返す return this.pachimonCoordinatesMap.get(type); } } /** * 座標を表現するクラス */ static class Coordinate { private int x; private int y; private boolean isGoal; // ゴールの座標か否か Coordinate(int x, int y) { this.x = x; this.y = y; } Coordinate(int x, int y, boolean isGoal) { this.x = x; this.y = y; this.isGoal = isGoal; } int calcCost(Coordinate another) { // 渡された座標に移動するまでのコスト(移動数)を計算して返す int xCost = Math.abs(another.x - this.x); int yCost = Math.abs(another.y - this.y); return xCost + yCost; } boolean isGoal() { return this.isGoal; } } /** * パチクリの属性を表現するクラス */ enum PachimonType { FIRE(1), ICE(2), WOOD(3), EARTH(4), WATER(5); PachimonType(int i) { this.value = i; } private int value; int getValue() { return this.value; } static PachimonType valueOf(int i) { if (i == FIRE.value) return FIRE; else if (i == ICE.value) return ICE; else if (i == WOOD.value) return WOOD; else if (i == EARTH.value) return EARTH; else if (i == WATER.value) return WATER; else throw new IllegalArgumentException(); } @SuppressWarnings("serial") static List<PachimonType> getPachimonTypeList() { return new ArrayList<PachimonCreature.PachimonType>() {{ add(FIRE); add(ICE); add(WOOD); add(EARTH); add(WATER); }}; } } static List<List<String>> getMapStringsList() { Scanner scanner = null; List<String> inputList = new ArrayList<String>(); try { scanner = new Scanner(System.in); while (scanner.hasNext()) { inputList.add(scanner.nextLine()); } } finally { if (scanner != null) { scanner.close(); } } List<List<String>> mapStringsList = new ArrayList<List<String>>(); int startLineNumber = 0; // マップの読み取りを開始する行番号 int mapLineSize = Character.getNumericValue(inputList.get(0).charAt(2)); // マップの行数 // 入力された文字列からデータセットごとにマップを取り出してListに格納する while (true) { List<String> mapStrings = getMapStrings(inputList, startLineNumber, mapLineSize); if (mapStrings.isEmpty()) { break; } mapStringsList.add(mapStrings); // 次に読み取るデータセット用に更新 startLineNumber = startLineNumber + mapLineSize + 1; mapLineSize = Character.getNumericValue(inputList.get(startLineNumber).charAt(2)); } return mapStringsList; } static List<String> getMapStrings(List<String> inputList, int startLineNumber, int mapLineSize) { List<String> list = new ArrayList<String>(); if (mapLineSize == 0) { // 入力の終り return list; } for (int i = 1; i <= mapLineSize; i++) { list.add(inputList.get(i + startLineNumber)); } return list; } }
Main.java:10: error: class PachimonCreature is public, should be declared in a file named PachimonCreature.java public class PachimonCreature { ^ 1 error
s627047537
p00215
Java
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Scanner; public class Main { public static void main(String... args) { for (List<String> mapStrings : getMapStringsList()) { if (mapStrings.isEmpty()) { break; } // マップの文字列をもとに全ての座標を生成する Coordinates coordinates = new Coordinates(mapStrings); // ゴールまでの最短経路を探索して出力する PachimonCreaturePlayer player = new PachimonCreaturePlayer(); player.completeGame(coordinates); player.output(); } } static class PachimonCreaturePlayer { private PachimonType firstType; // 最初に選ぶべきパチクリの属性 private int minCost; // 最小移動数 void completeGame(Coordinates coordinates) { // 捕まえるパチクリの属性の順番と、最初に選ぶパチクリの属性を生成する // (例:「火」⇒「氷」⇒「木」⇒「土」の順で捕まえる場合、順番の最後の属性「水」が最初に選ぶパチクリの属性となる) List<PachimonType> typeList = PachimonType.getPachimonTypeList(); LinkedList<PachimonType> orderToCatch = new LinkedList<PachimonType>(); for (PachimonType type : typeList) { orderToCatch.add(type); } // 最初に選ぶパチクリの属性5パターンすべてについて、 // 順番通りにパチクリを捕まえていったときの最小移動数を取得する for (int i = 0; i < 5; i++) { int cost = getMinCostWithPachimonType(coordinates, orderToCatch); if (i == 0 || (cost < this.minCost && 0 < cost)) { // 現在保持している最小移動数より小さい場合にはそちらで上書きする this.minCost = cost; this.firstType = orderToCatch.peekLast(); } // 捕まえる属性の順番を1つずらす PachimonType head = orderToCatch.poll(); orderToCatch.add(head); } } private int getMinCostWithPachimonType(Coordinates coordinates, List<PachimonType> orderToCatch) { // スタート位置の座標をルートノードとする Node startNode = new Field(coordinates.getStart(), 0, 0); // 属性ごとに全ての座標を取得し、スタート位置を頂点とする木構造を構築する // (レベル0・・・スタート位置の座標、レベル1・・・属性Aのパチクリの全座標、レベル2・・・属性Bのパチクリの全座標 ・・・) for (int i = 0; i < 4; i++) { List<Coordinate> coordinatesOfType = coordinates.getTypeList(orderToCatch.get(i)); if (coordinatesOfType.isEmpty()) { // 捕まえられるパチクリがいない場合 return 0; } for (Coordinate coordinate : coordinatesOfType) { startNode.add(coordinate, i + 1); } } // ゴール位置の座標をリーフとする startNode.add(coordinates.getGoal(), 5); // スタート(ルート)からゴール(リーフ)までの木構造を辿り、最小移動数を返す return startNode.getMinCostToGoal(); } void output() { if (this.minCost == 0) { System.out.println("NA"); } else { System.out.println(this.firstType.getValue() + " " + this.minCost); } } } /** * 移動経路を構成する木構造の各ノードを表現するクラス */ static abstract class Node { protected int level; // 木構造における本ノードのレベル protected int costFromStart; // スタート位置(ルート)からの移動数 protected Coordinate coordinate; // 本ノードのマップ上における座標 Node(Coordinate coordinate, int level, int costFromStart) { this.coordinate = coordinate; this.level = level; this.costFromStart = costFromStart; } void add(Coordinate coordinate, int level) { throw new UnsupportedOperationException(); } abstract int getMinCostToGoal(); } /** * ノードのうち、ゴール位置以外のノードを表現するクラス。子ノードを持つ。 */ static class Field extends Node { private List<Node> childNodes = new ArrayList<Node>(); // 子ノード Field(Coordinate coordinate, int level, int costFromStart) { super(coordinate, level, costFromStart); } void add(Coordinate coordinate, int level) { if (level - this.level == 1) { // 自分の直下レベルであれば自分の子ノードに追加する int cost = this.coordinate.calcCost(coordinate) + this.costFromStart; this.childNodes.add(coordinate.isGoal ? new Goal(coordinate, level, cost) : new Field(coordinate, level, cost)); return; } // それより下のレベルであれば全ての子ノードに処理を委譲 for (Node childNode : childNodes) { childNode.add(coordinate, level); } } @Override int getMinCostToGoal() { // 全ての子ノードを辿ってゴール(リーフ)までの移動数を取得し、そのうちの最小のものを返す List<Integer> list = new ArrayList<Integer>(); for (Node node : this.childNodes) { list.add(node.getMinCostToGoal()); } return Collections.min(list); } } /** * ノードのうち、ゴール位置を表現するクラス。子ノードを持たない。 */ static class Goal extends Node { Goal(Coordinate coordinates, int level, int costFromStart) { super(coordinates, level, costFromStart); } @Override int getMinCostToGoal() { return this.costFromStart; } } /** * 全ての座標を保持するクラス */ static class Coordinates { private Coordinate start; // スタートの座標 private Coordinate goal; // ゴールの座標 // 属性をキーとし、その属性のパチクリの位置座標リストを値として持つMap private Map<PachimonType, List<Coordinate>> pachimonCoordinatesMap = new HashMap<PachimonType, List<Coordinate>>(); Coordinates(List<String> lines) { // 全属性分の位置座標リストを用意してMapに格納する List<PachimonType> pachimonTypeList = PachimonType.getPachimonTypeList(); for (PachimonType type : pachimonTypeList) { this.pachimonCoordinatesMap.put(type, new ArrayList<Coordinate>()); } // マップを走査してスタート、ゴール、パチクリの全座標を取得して格納する int x = 0; for (String line : lines) { int y = 0; for (char c : line.toCharArray()) { String str = String.valueOf(c); if (str.equals("S")) { this.start = new Coordinate(x, y); } else if (str.equals("G")) { this.goal = new Coordinate(x, y, true); } else if (str.equals(".")) { // なにもしない } else { PachimonType type = PachimonType.valueOf(Integer.parseInt(str)); Coordinate coordinates = new Coordinate(x, y); this.pachimonCoordinatesMap.get(type).add(coordinates); } y++; } x++; } } Coordinate getStart() { return this.start; } Coordinate getGoal() { return this.goal; } List<Coordinate> getTypeList(PachimonType type) { // 指定された属性のパチクリの座標リストを返す return this.pachimonCoordinatesMap.get(type); } } /** * 座標を表現するクラス */ static class Coordinate { private int x; private int y; private boolean isGoal; // ゴールの座標か否か Coordinate(int x, int y) { this.x = x; this.y = y; } Coordinate(int x, int y, boolean isGoal) { this.x = x; this.y = y; this.isGoal = isGoal; } int calcCost(Coordinate another) { // 渡された座標に移動するまでのコスト(移動数)を計算して返す int xCost = Math.abs(another.x - this.x); int yCost = Math.abs(another.y - this.y); return xCost + yCost; } boolean isGoal() { return this.isGoal; } } /** * パチクリの属性を表現するクラス */ enum PachimonType { FIRE(1), ICE(2), WOOD(3), EARTH(4), WATER(5); PachimonType(int i) { this.value = i; } private int value; int getValue() { return this.value; } static PachimonType valueOf(int i) { if (i == FIRE.value) return FIRE; else if (i == ICE.value) return ICE; else if (i == WOOD.value) return WOOD; else if (i == EARTH.value) return EARTH; else if (i == WATER.value) return WATER; else throw new IllegalArgumentException(); } @SuppressWarnings("serial") static List<PachimonType> getPachimonTypeList() { return new ArrayList<PachimonCreature.PachimonType>() {{ add(FIRE); add(ICE); add(WOOD); add(EARTH); add(WATER); }}; } } static List<List<String>> getMapStringsList() { Scanner scanner = null; List<String> inputList = new ArrayList<String>(); try { scanner = new Scanner(System.in); while (scanner.hasNext()) { inputList.add(scanner.nextLine()); } } finally { if (scanner != null) { scanner.close(); } } List<List<String>> mapStringsList = new ArrayList<List<String>>(); int startLineNumber = 0; // マップの読み取りを開始する行番号 int mapLineSize = Character.getNumericValue(inputList.get(0).charAt(2)); // マップの行数 // 入力された文字列からデータセットごとにマップを取り出してListに格納する while (true) { List<String> mapStrings = getMapStrings(inputList, startLineNumber, mapLineSize); if (mapStrings.isEmpty()) { break; } mapStringsList.add(mapStrings); // 次に読み取るデータセット用に更新 startLineNumber = startLineNumber + mapLineSize + 1; mapLineSize = Character.getNumericValue(inputList.get(startLineNumber).charAt(2)); } return mapStringsList; } static List<String> getMapStrings(List<String> inputList, int startLineNumber, int mapLineSize) { List<String> list = new ArrayList<String>(); if (mapLineSize == 0) { // 入力の終り return list; } for (int i = 1; i <= mapLineSize; i++) { list.add(inputList.get(i + startLineNumber)); } return list; } }
Main.java:273: error: package PachimonCreature does not exist return new ArrayList<PachimonCreature.PachimonType>() {{ ^ 1 error
s804569283
p00215
Java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { /** ゲームごとのマップのリスト */ private static List<String[][]> mapList = new ArrayList<String[][]>(); /** スタート地点を表す文字 */ private static final String START = "S"; public static void main(String[] args) throws IOException { // 入力値の読み込み setMapOnGames(); for (String[][] map : mapList) { // 各属性が座標のどこにいるかを求める Map<String, List<String>> attributeMap = getAttributeMap(map); // すべての属性がそろっていない場合は、"NA"を出力 if (attributeMap.keySet().size() != 7) { System.out.println("NA"); continue; } // 移動数が最小となるスタート時の属性と移動数を求める String minAttribute = null; int minMoveCount = Integer.MAX_VALUE; for (int i = 1; i <= 5; i++) { String startAttribute = String.valueOf(i); int totalMoveCount = calcTotalMoveCount(attributeMap, attributeMap.get(START).get(0), String.valueOf(i), 1); if (totalMoveCount < minMoveCount) { minAttribute = startAttribute; minMoveCount = totalMoveCount; } } System.out.println(minAttribute + " " + minMoveCount); } } /** * <p> * 入力値を取得し、Gameクラスにセットする * </p> * * @throws IOException */ private static void setMapOnGames() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = null; while ((line = br.readLine()) != null) { // 空のマップを作成する String[] mapSize = line.split(" "); int sizeX = Integer.parseInt(mapSize[0]); int sizeY = Integer.parseInt(mapSize[1]); String[][] map = new String[sizeY][sizeX]; // マップの情報をセットする for (String[] xMap : map) { String xLine = br.readLine(); for (int i = 0; i < sizeX; i++) { xMap[i] = String.valueOf(xLine.charAt(i)); } } mapList.add(map); } } private static Map<String, List<String>> getAttributeMap(String[][] map) { Map<String, List<String>> attributeMap = new HashMap<String, List<String>>(); ; // マップから、各属性が存在する座標を取り出し、属性存在Mapに退避する int y = 0; for (String[] xMap : map) { int x = 0; for (String str : xMap) { if (!".".equals(str)) { if (!attributeMap.containsKey(str)) { attributeMap.put(str, new ArrayList<String>()); } attributeMap.get(str).add(x + "," + y); } x++; } y++; } return attributeMap; } private static int calcMoveCount(String from, String to) { // 移動元の座標を取得 String[] fromPoint = from.split(","); int fromPointX = Integer.parseInt(fromPoint[0]); int fromPointY = Integer.parseInt(fromPoint[1]); // 移動先の座標を取得 String[] toPoint = to.split(","); int toPointX = Integer.parseInt(toPoint[0]); int toPointY = Integer.parseInt(toPoint[1]); // 絶対値で計算 return Math.abs(fromPointX - toPointX) + Math.abs(fromPointY - toPointY); } private static int calcTotalMoveCount( Map<String, List<String>> attributeMap, String coordinates, String lastAttribute, int creatures) { int totalMoveCount = Integer.MAX_VALUE; if (creatures == 5) { // パチモンが5匹集まっていたら、ゴールへの移動数を足して返す totalMoveCount = calcMoveCount(coordinates, attributeMap.get("G") .get(0)); } else { // このターンで獲得できる属性を取得 String attribute = getNextAttribute(lastAttribute); // 次の属性の座標を取得し、再帰的に探索 for (String nextCoordinates : attributeMap.get(attribute)) { int tmpMoveCount = calcMoveCount(coordinates, nextCoordinates) + calcTotalMoveCount(attributeMap, nextCoordinates, attribute, creatures + 1); if (tmpMoveCount < totalMoveCount) { totalMoveCount = tmpMoveCount; } } } return totalMoveCount; } private static String getNextAttribute(String attribute) { int nextNumber = Integer.parseInt(attribute) + 1; if (nextNumber == 6) { nextNumber = 1; } return String.valueOf(nextNumber); }
Main.java:161: error: reached end of file while parsing } ^ 1 error
s949009992
p00215
Java
import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class P0215 { int INF = 1 << 28; int[][] map; P s, g; int w, h, node; void run() { Scanner sc = new Scanner(System.in); for(;;) { w = sc.nextInt(); h = sc.nextInt(); if((w|h) == 0) break; LinkedList<P>[] d = new LinkedList[5]; for(int i=0;i<5;i++) d[i] = new LinkedList<P>(); node = 0; for(int i=0;i<h;i++) { String str = sc.next(); for(int j=0;j<str.length();j++) { switch(str.charAt(j)) { case 'S': s = new P(j, i, node); break; case 'G': g = new P(j, i, node); break; case '.': continue; default : d[str.charAt(j)-'1'].add(new P(j, i, node)); } node++; } } map = new int[node][node]; for(int[] a: map) fill(a, INF); for(LinkedList<P> list: d) { for(P p: list) { map[s.ind][p.ind] = abs(s.x-p.x) + abs(s.y-p.y); map[p.ind][g.ind] = abs(p.x-g.x) + abs(p.y-g.y); } } for(int i=0;i<5;i++) { for(P p1: d[i]) for(P p2: d[(i+1)%5]) { map[p1.ind][p2.ind] = abs(p1.x-p2.x) + abs(p1.y-p2.y); } } int min = dijkstra(); if(min == INF) System.out.println("NA"); else { int p = g.ind; while(visit[p] != s.ind) { p = visit[p]; } for(int i=0;i<5;i++) { boolean f = false; for(P p1: d[i]) { if(p1.ind == p) { f = true; break; } } if(f) { System.out.println(i + " " + min); break; } } } } } int visit[]; int dijkstra() { int[] d = new int[node]; boolean visited[] = new boolean[node]; visit = new int[node]; fill(visited, false); fill(d, INF); d[s.ind] = 0; for(;;) { int v = -1; int min = INF; for(int i=0;i<node;i++) { if( min > d[i] && !visited[i] ) { v = i; min = d[i]; } } if(v < 0) break; if(v == g.ind) break; visited[v] = true; for(int u=0;u<node;u++) { if(d[u] > d[v] + map[v][u]) { d[u] = d[v] + map[v][u]; visit[u] = v; } } } return d[g.ind]; } public static void main(String[] args) { new P0215().run(); } class P { int x, y, ind; P(int x, int y, int ind) { this.x = x; this.y = y; this.ind = ind; } } }
Main.java:7: error: class P0215 is public, should be declared in a file named P0215.java public class P0215 { ^ Note: Main.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error
s875605741
p00215
C
#include <cstdio> #include <cstdlib> #include <cstring> #include <climits> #include <cmath> #include <cassert> #include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <numeric> #include <complex> #include <list> #include <stack> #include <queue> #include <set> #include <map> #include <bitset> #include <utility> #include <functional> #include <iterator> using namespace std; #define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl #define repi(i,a,b) for(int i=int(a);i<int(b);i++) #define peri(i,a,b) for(int i=int(b);i-->int(a);) #define rep(i,n) repi(i,0,n) #define per(i,n) peri(i,0,n) #define iter(c) __typeof__((c).begin()) #define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i) #define all(c) (c).begin(),(c).end() #define mp make_pair typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<string> vs; typedef pair<int,int> pii; const int INFTY=1<<29; struct State{ int i,j,cost,bit; State(){} State(int i,int j,int c,int b):i(i),j(j),cost(c),bit(b){} }; int solve(vs& grid,pii start,pii goal,int firstbit) { int h=grid.size(),w=grid[0].size(); vector<vvi> vis(h,vvi(w,vi(1<<5))); queue<State> q; q.push(State(start.first,start.second,0,firstbit)); while(q.size()){ State cur=q.front(); q.pop(); if(cur.bit==31 && mp(cur.i,cur.j)==goal) return cur.cost; if(vis[cur.i][cur.j][cur.bit]) continue; vis[cur.i][cur.j][cur.bit]=1; int di[]={-1,1,0,0},dj[]={0,0,-1,1}; rep(k,4){ int ni=cur.i+di[k],nj=cur.j+dj[k]; if(ni<0 || h<=ni || nj<0 || w<=nj) continue; if(grid[ni][nj]=='.') q.push(State(ni,nj,cur.cost+1,cur.bit)); else{ int m=grid[ni][nj]-'1'; if(cur.bit&(1<<(m+4)%5)) q.push(State(ni,nj,cur.cost+1,cur.bit|1<<m)); else q.push(State(ni,nj,cur.cost+1,cur.bit)); } } } return INFTY; } int main() { for(int w,h;cin>>w>>h,w|h;){ vs grid(h); rep(i,h) cin>>grid[i]; pii start,goal; rep(i,h) rep(j,w){ if(grid[i][j]=='S'){ start=mp(i,j); grid[i][j]='.'; } if(grid[i][j]=='G'){ goal=mp(i,j); grid[i][j]='.'; } } pii res(INFTY,-1); rep(i,5){ int tmp=solve(grid,start,goal,1<<i); res=min(res,mp(tmp,i)); } if(res.second==-1) cout<<"NA"<<endl; else cout<<res.second+1<<' '<<res.first<<endl; } return 0; }
main.c:1:10: fatal error: cstdio: No such file or directory 1 | #include <cstdio> | ^~~~~~~~ compilation terminated.
s602171356
p00215
C++
import java.util.*; @SuppressWarnings("unchecked") class Main{ int w, h; //char[][] map; ArrayList[] list; void solve(){ Scanner sc = new Scanner(System.in); while(true){ w = sc.nextInt(); h = sc.nextInt(); if(w==0 && h==0) break; list = new ArrayList[5]; for(int i=0; i<5; i++) list[i] = new ArrayList<int[]>(); int sx = 0, sy = 0; int gx = 0, gy = 0; for(int i=0; i<h; i++){ char[] line = sc.next().toCharArray(); for(int j=0; j<w; j++){ if(line[j]=='S'){ sx = j; sy = i;} if(line[j]=='G'){ gx = j; gy = i;} if(Character.isDigit(line[j])) list[line[j]-'1'].add(new int[]{j, i}); } } int idx = 0, min = Integer.MAX_VALUE; for(int i=0; i<5; i++){ int num = bfs(sx, sy, gx, gy, i); if(num==-1) continue; if(num<min){ min = num; idx = i; } } idx++; if(min==Integer.MAX_VALUE) System.out.println("NA"); else System.out.println(idx+" "+min); } } int bfs(int sx, int sy, int gx, int gy, int pati){ //pos, nextpati, dist PriorityQueue<int[]> q = new PriorityQueue<int[]>(10, new Comparator<int[]>(){ public int compare(int[] a, int[] b){ return a[3] - b[3]; } }); q.add(new int[]{sx, sy, (pati+1)%5, 0}); while(q.size()>0){ int[] qq = q.poll(); int x = qq[0], y = qq[1], nextpati = qq[2], dist = qq[3]; if(nextpati==pati) return dist; for(int i=0; i<list[nextpati].size(); i++){ int[] qqq = (int[])list[nextpati].get(i); int nx = qqq[0], ny = qqq[1]; int ndist = dist+Math.abs(x-nx)+Math.abs(y-ny); if((nextpati+1)%5==pati) ndist += Math.abs(nx-gx)+Math.abs(ny-gy); q.add(new int[]{nx, ny, (nextpati+1)%5, ndist}); } } return -1; } public static void main(String[] args){ new Main().solve(); } }
a.cc:3:1: error: stray '@' in program 3 | @SuppressWarnings("unchecked") | ^ 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:3:18: error: expected constructor, destructor, or type conversion before '(' token 3 | @SuppressWarnings("unchecked") | ^
s734078577
p00215
C++
#include<cstdio> #include<vector> #include<map> #include<algorithm> #include<cstring> #define INF 1<<28 #define F first #define S second using namespace std; int sx, sy, gx, gy; typedef pair < int, int > P; vector < P > p[5]; int memo[5][5][1111]; int dist(P a, P b){ return abs(a.F - b.F) + abs(a.S, b.S); } int solve(int k, int t, int q){ if(k == 4) return abs(p[t][q].F-gx) + abs(p[t][q].S-gy); if(memo[k][t][q]) return memo[k][t][q]; int ans = INF, d = (t+1)%5, c; for(int i=0;i<p[d].size();i++){ if(!k) c = abs(sx-p[d][i].F) + abs(sy-p[d][i].S); else c = abs(p[t][q].F-p[d][i].F) + abs(p[t][q].S-p[d][i].S); ans = min(ans, solve(k+1, d, i) + c); } return memo[k][t][q] = ans; } int main(){ int w, h; char c; while(scanf("%d %d", &w, &h), w){ for(int i=0;i<5;i++) p[i].clear(); for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ scanf(" %c", &c); if(c == '.') continue; else if(c == 'S') sx = j, sy = i; else if(c == 'G') gx = j, gy = i; else p[c-'1'].push_back(P(j,i)); } } int a, b = INF; for(int i=0;i<5;i++){ memset(memo, 0, sizeof(memo)); if(b > solve(0,i,0)) a = i+1, b = solve(0,i,0); } if(b == INF) puts("NA"); else printf("%d %d\n", a, b); } }
a.cc: In function 'int dist(P, P)': a.cc:17:30: error: no matching function for call to 'abs(int&, int&)' 17 | return abs(a.F - b.F) + abs(a.S, b.S); | ~~~^~~~~~~~~~ In file included from /usr/include/c++/14/cstdlib:79, from /usr/include/c++/14/bits/stl_algo.h:71, from /usr/include/c++/14/algorithm:61, from a.cc:4: /usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)' 980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur; | ^~~ /usr/include/stdlib.h:980:12: note: candidate expects 1 argument, 2 provided In file included from /usr/include/c++/14/cstdlib:81: /usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)' 137 | abs(__float128 __x) | ^~~ /usr/include/c++/14/bits/std_abs.h:137:3: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)' 85 | abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; } | ^~~ /usr/include/c++/14/bits/std_abs.h:85:3: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)' 79 | abs(long double __x) | ^~~ /usr/include/c++/14/bits/std_abs.h:79:3: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)' 75 | abs(float __x) | ^~~ /usr/include/c++/14/bits/std_abs.h:75:3: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)' 71 | abs(double __x) | ^~~ /usr/include/c++/14/bits/std_abs.h:71:3: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)' 61 | abs(long long __x) { return __builtin_llabs (__x); } | ^~~ /usr/include/c++/14/bits/std_abs.h:61:3: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)' 56 | abs(long __i) { return __builtin_labs(__i); } | ^~~ /usr/include/c++/14/bits/std_abs.h:56:3: note: candidate expects 1 argument, 2 provided
s751770561
p00215
C++
#include<cstdio> #include<vector> #include<map> #include<algorithm> #include<cstring> #define INF 1<<28 #define F first #define S second using namespace std; int sx, sy, gx, gy; typedef pair < int, int > P; vector < P > v[5]; int memo[5][5][1111]; int dist(P a, P b){ return abs(a.F - b.F) + abs(a.S - b.S); } int solve(int cnt, int now, int p){ if(cnt == 4) return dist(v[now][p], P(gx, gy)); if(memo[cnt][now][p]) return memo[cnt][now][p]; int ans = INF, next = (now+1)%5, cost; for(int i=0;i<v[next].size();i++){ if(!cnt) cost = dist(P(sx, sy), v[next][i]); else cost = dist(v[now][p], v[next][i]); ans = min(ans, solve(cnt+1, next, i) + cost); } return memo[cnt][now][p] = ans; } int main(){ int w, h; char c; while(scanf("%d %d", &w, &h), w){ for(int i=0;i<5;i++) v[i].clear(); for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ scanf(" %c", &c); if(c == '.') continue; else if(c == 'S') sx = j, sy = i; else if(c == 'G') gx = j, gy = i; else v[c-'1'].push_back( P(j,i) ); } } int a, b = INF; for(int i=0;i<5;i++){ memset(memo, 0, sizeof(memo)); if(b > solve(0,i,0)) a = i+1, b = solve(0,i,0); } b == INF:puts("NA"):printf("%d %d\n", a, b); } }
a.cc: In function 'int main()': a.cc:61:13: error: expected ';' before ':' token 61 | b == INF:puts("NA"):printf("%d %d\n", a, b); | ^
s273295002
p00215
C++
import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.PriorityQueue; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { new Main().run(); } private void run() throws IOException { Scanner scanner = new Scanner(System.in); while (true) { int w = scanner.nextInt(); int h = scanner.nextInt(); if ((w | h) == 0) break; list = new ArrayList<List<Pair>>(); for (int i = 0; i < 6; i++) { list.add(new ArrayList<Pair>()); } for (int i = 0; i < h; i++) { char[] cs = scanner.next().toCharArray(); for (int j = 0; j < w; j++) { if (cs[j] == 'S') { sy = i; sx = j; } else if (cs[j] == 'G') { gy = i; gx = j; } else if (cs[j] != '.') { list.get(Character.getNumericValue(cs[j])).add( new Pair(i, j)); } } } min = Integer.MAX_VALUE; int index = -1; for (int i = 1; i < 6; i++) { int cos = slove(i, i == 1 ? 5 : i - 1); if (min > cos) { min = cos; index = i; } } System.out.println(index == -1 ? "NA" : index + " " + min); } } private int slove(int k, int g) { PriorityQueue<Pair> pq = new PriorityQueue<>(); int s = k == 5 ? 1 : k + 1; for (int i = 0; i < list.get(s).size(); i++) { int y = list.get(s).get(i).y; int x = list.get(s).get(i).x; int dis = Math.abs(y - sy) + Math.abs(x - sx); pq.add(new Pair(y, x, dis, k + 1)); } while (!pq.isEmpty()) { Pair pair = pq.poll(); int y = pair.y; int x = pair.x; int cost = pair.cost; int id = pair.id; int tmpid = id > 5 ? id - 5 : id; if(min<=cost) return Integer.MAX_VALUE; if (id == 10) { return cost; } if (tmpid != g) { for (Pair i : list.get(tmpid == 5 ? 1 : tmpid + 1)) { int dis = Math.abs(y - i.y) + Math.abs(x - i.x); pq.add(new Pair(i.y, i.x, cost + dis, id + 1)); } } else { int dis = Math.abs(y - gy) + Math.abs(x - gx); pq.add(new Pair(0, 0, cost + dis, 10)); } } return Integer.MAX_VALUE; } List<List<Pair>> list; int sy; int gy; int sx; int gx; int min; class Pair implements Comparable<Pair> { int y; int x; int cost; int id; @Override public int compareTo(Pair o) { if (this.cost == o.cost) return o.id - this.id; return this.cost - o.cost; } public Pair(int y, int x) { super(); this.y = y; this.x = x; } public Pair(int y, int x, int cost, int id) { super(); this.y = y; this.x = x; this.cost = cost; this.id = id; } } }
a.cc:102:17: error: stray '@' in program 102 | @Override | ^ a.cc:2:1: error: 'import' does not name a type 2 | import java.io.IOException; | ^~~~~~ 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.util.ArrayList; | ^~~~~~ 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.List; | ^~~~~~ 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 java.util.PriorityQueue; | ^~~~~~ 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 java.util.Scanner; | ^~~~~~ a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:8:1: error: expected unqualified-id before 'public' 8 | public class Main { | ^~~~~~
s837821852
p00215
C++
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.Comparator; class Point { public static int nextId = 0; public int id; public int x; public int y; public int distanceFromStart; public List<Point> nextPointList; public boolean canGoGoal; public Point(int x, int y) { this.id = nextId++; this.x = x; this.y = y; this.distanceFromStart = Integer.MAX_VALUE; this.canGoGoal = false; } public int distance(Point p) { return Math.abs(this.x - p.x) + Math.abs(this.y - p.y); } } public class Main { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static Point start = null; public static Point goal = null; public static int pointCount = 0; //パチモンのタイプ毎の頂点リスト public static List<List<Point> > pointListByType = new ArrayList<List<Point> >(); static { // 枠だけ用意 for(int i = 0; i < 5; i++) { pointListByType.add(new ArrayList<Point>()); } } public static void main(String args[]) throws IOException { while(true) { String mapSizeStr = br.readLine(); if("0 0".equals(mapSizeStr)) break; String[] splittedStr = mapSizeStr.split(" "); int x = Integer.parseInt(splittedStr[0]); int y = Integer.parseInt(splittedStr[1]); for(int i = 0; i < 5; i++) { pointListByType.get(i).clear(); } pointCount = 0; Point.nextId = 0; for(int r = 0; r < y; r++){ String line = br.readLine(); for(int c = 0; c < x; c++) { char pointLiteral = line.charAt(c); switch(pointLiteral) { case 'S': start = new Point(c, r); start.nextPointList = new ArrayList<Point>(); pointCount++; break; case 'G': goal = new Point(c, r); goal.nextPointList = new ArrayList<Point>(); pointCount++; break; case '1':case '2':case '3':case '4':case '5': int type = (int)pointLiteral - (int)'1'; pointListByType.get(type).add(new Point(c, r)); pointCount++; break; } } } //到達不可能判定 //1匹もパチモンがいない属性が2つ以上あれば、到達不能 int zeroTypeCount = 0; for(int i = 0 ; i < 5; i++) { if(pointListByType.get(i).size() == 0) { if(++zeroTypeCount >= 2) { break; } } } if(zeroTypeCount >= 2) { System.out.println("NA"); continue; } // 各属性間のつながりを生成 List<Point> firePointList = pointListByType.get(0); List<Point> icePointList = pointListByType.get(1); List<Point> treePointList = pointListByType.get(2); List<Point> earthPointList = pointListByType.get(3); List<Point> waterPointList = pointListByType.get(4); // fire to ice for (Point p : firePointList) { p.nextPointList = icePointList; } // ice to tree for (Point p : icePointList) { p.nextPointList = treePointList; } // tree to earth for (Point p : treePointList) { p.nextPointList = earthPointList; } // earth to water for (Point p : earthPointList) { p.nextPointList = waterPointList; } // water to fire for (Point p : waterPointList) { p.nextPointList = firePointList; } // 各属性を最初に選んだ場合についてそれぞれ最短経路を求める int minLenType = -1; int minLen = Integer.MAX_VALUE; for (int firstType = 0; firstType < 5; firstType++) { //最初の一匹以外のいずれかの属性のパチモンがいない場合到達不能 if( firstType == 0 && ( pointListByType.get(1).size() == 0 || pointListByType.get(2).size() == 0 || pointListByType.get(3).size() == 0 || pointListByType.get(4).size() == 0 ) || firstType == 1 && ( pointListByType.get(0).size() == 0 || pointListByType.get(2).size() == 0 || pointListByType.get(3).size() == 0 || pointListByType.get(4).size() == 0 ) || firstType == 2 && ( pointListByType.get(0).size() == 0 || pointListByType.get(1).size() == 0 || pointListByType.get(3).size() == 0 || pointListByType.get(4).size() == 0 ) || firstType == 3 && ( pointListByType.get(0).size() == 0 || pointListByType.get(1).size() == 0 || pointListByType.get(2).size() == 0 || pointListByType.get(4).size() == 0 ) || firstType == 4 && ( pointListByType.get(0).size() == 0 || pointListByType.get(1).size() == 0 || pointListByType.get(2).size() == 0 || pointListByType.get(3).size() == 0 ) ) { continue; } //make graph start.nextPointList.clear(); for(int i = 0; i < 5; i++) { // from Start to evry point expect Goal if(i == (firstType + 1) % 5) { start.nextPointList.addAll(pointListByType.get(i)); } } for(int j = 0; j < pointListByType.get((firstType + 4) % 5).size(); j++) { pointListByType.get((firstType + 4) % 5).get(j).canGoGoal = true; } //search shortest path int shortestPathLen = searchShortestPath(); if(minLen > shortestPathLen) { minLen = shortestPathLen; minLenType = firstType; } // 計算で更新された項目の初期化 for(int j = 0; j < pointListByType.get((firstType + 4) % 5).size(); j++) { pointListByType.get((firstType + 4) % 5).get(j).canGoGoal = false; } for(int i = 0; i < 5; i++) { List<Point> tempPointList = pointListByType.get(i); for(int j = 0; j < tempPointList.size(); j++) { Point tempPoint = tempPointList.get(j); tempPoint.distanceFromStart = Integer.MAX_VALUE; } } goal.distanceFromStart = Integer.MAX_VALUE; } if(minLen == Integer.MAX_VALUE) { System.out.println("NA"); } else { System.out.println((minLenType + 1) + " " + minLen); } } } private static int searchShortestPath() { start.distanceFromStart = 0; int searchedPointCount = 0; Point searchingPoint = start; PriorityQueue<Point> q = new PriorityQueue<Point>( pointCount, new Comparator<Point>() { @Override public int compare(Point p1, Point p2) { if(p1.distanceFromStart != p2.distanceFromStart) { return p1.distanceFromStart - p2.distanceFromStart; } return p1.id - p2.id; } } ); q.add(start); while(!q.isEmpty()) { //スタートからの距離が最小のものを頂点集合から削除 searchingPoint = q.poll(); if(searchingPoint.id == goal.id) break; if(searchingPoint.canGoGoal) { int distance = searchingPoint.distance(goal); if(goal.distanceFromStart > searchingPoint.distanceFromStart + distance) { goal.distanceFromStart = searchingPoint.distanceFromStart + distance; q.add(goal); } } //検索中のノードから繋がっているものを走査 for(Point tempNextPoint : searchingPoint.nextPointList) { //if(!q.contains(tempNextPoint)) continue; int distance = searchingPoint.distance(tempNextPoint); if(tempNextPoint.distanceFromStart > searchingPoint.distanceFromStart + distance) { tempNextPoint.distanceFromStart = searchingPoint.distanceFromStart + distance; q.add(tempNextPoint); } } } //探索完了 return goal.distanceFromStart; } }
a.cc:224:33: error: stray '@' in program 224 | @Override | ^ a.cc:1:1: error: 'import' does not name a type 1 | import java.io.BufferedReader; | ^~~~~~ 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.io.InputStreamReader; | ^~~~~~ 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.IOException; | ^~~~~~ 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.Arrays; | ^~~~~~ 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 java.util.List; | ^~~~~~ 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 java.util.ArrayList; | ^~~~~~ 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 java.util.PriorityQueue; | ^~~~~~ a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:8:1: error: 'import' does not name a type 8 | import java.util.Comparator; | ^~~~~~ a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:11:11: error: expected ':' before 'static' 11 | public static int nextId = 0; | ^~~~~~~ | : a.cc:11:23: error: ISO C++ forbids in-class initialization of non-const static member 'Point::nextId' 11 | public static int nextId = 0; | ^~~~~~ a.cc:13:11: error: expected ':' before 'int' 13 | public int id; | ^~~~ | : a.cc:14:11: error: expected ':' before 'int' 14 | public int x; | ^~~~ | : a.cc:15:11: error: expected ':' before 'int' 15 | public int y; | ^~~~ | : a.cc:16:11: error: expected ':' before 'int' 16 | public int distanceFromStart; | ^~~~ | : a.cc:17:11: error: expected ':' before 'List' 17 | public List<Point> nextPointList; | ^~~~~ | : a.cc:17:12: error: 'List' does not name a type 17 | public List<Point> nextPointList; | ^~~~ a.cc:18:11: error: expected ':' before 'boolean' 18 | public boolean canGoGoal; | ^~~~~~~~ | : a.cc:18:12: error: 'boolean' does not name a type; did you mean 'bool'? 18 | public boolean canGoGoal; | ^~~~~~~ | bool a.cc:20:11: error: expected ':' before 'Point' 20 | public Point(int x, int y) { | ^~~~~~ | : a.cc:28:11: error: expected ':' before 'int' 28 | public int distance(Point p) { | ^~~~ | : a.cc:31:2: error: expected ';' after class definition 31 | } | ^ | ; a.cc: In constructor 'Point::Point(int, int)': a.cc:21:14: error: request for member 'id' in '(Point*)this', which is of pointer type 'Point*' (maybe you meant to use '->' ?) 21 | this.id = nextId++; | ^~ a.cc:22:14: error: request for member 'x' in '(Point*)this', which is of pointer type 'Point*' (maybe you meant to use '->' ?) 22 | this.x = x; | ^ a.cc:23:14: error: request for member 'y' in '(Point*)this', which is of pointer type 'Point*' (maybe you meant to use '->' ?) 23 | this.y = y; | ^ a.cc:24:14: error: request for member 'distanceFromStart' in '(Point*)this', which is of pointer type 'Point*' (maybe you meant to use '->' ?) 24 | this.distanceFromStart = Integer.MAX_VALUE; | ^~~~~~~~~~~~~~~~~ a.cc:24:34: error: 'Integer' was not declared in this scope 24 | this.distanceFromStart = Integer.MAX_VALUE; | ^~~~~~~ a.cc:25:14: error: request for member 'canGoGoal' in '(Point*)this', which is of pointer type 'Point*' (maybe you meant to use '->' ?) 25 | this.canGoGoal = false; | ^~~~~~~~~ a.cc: In member function 'int Point::distance(Point)': a.cc:29:16: error: 'Math' was not declared in this scope 29 | return Math.abs(this.x - p.x) + Math.abs(this.y - p.y); | ^~~~ a.cc:29:30: error: request for member 'x' in '(Point*)this', which is of pointer type 'Point*' (maybe you meant to use '->' ?) 29 | return Math.abs(this.x - p.x) + Math.abs(this.y - p.y); | ^ a.cc:29:55: error: request for member 'y' in '(Point*)this', which is of pointer type 'Point*' (maybe you meant to use '->' ?) 29 | return Math.abs(this.x - p.x) + Math.abs(this.y - p.y); | ^ a.cc: At global scope: a.cc:33:1: error: expected unqualified-id before 'public' 33 | public class Main { | ^~~~~~
s299766763
p00215
C++
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; const int MAX_V = 5050; const int INF = 1 << 15; short cost[MAX_V][MAX_V]; short d[MAX_V]; bool used[MAX_V]; int V; void dijkstra(int s) { fill(d, d + V, INF); fill(used, used + V, false); d[s] = 0; while (true){ int v = -1; for (int u = 0; u < V; u++){ if (!used[u] && (v == -1 || d[v] < d[v])) v = u; } if (v == -1) break; used[v] = true; for (int u = 0; u < V; u++){ d[u] = min(d[u], d[v] + cost[v][u]); } } } inline int dist(const P& a, const P& b){ return abs(a.first - b.first) + abs(a.second - b.second); } int main() { int w, h; while (scanf("%d %d", &w, &h), w){ vector<P> ps[5]; vector<int> is[5]; P start, goal; for (int y = 0; y < h; y++){ char line[1024]; scanf("%s", line); for (int x = 0; x < w; x++){ if (line[x] == 'S') start = P(x, y); else if (line[x] == 'G') goal = P(x, y); else if (line[x] != '.') { int id = line[x] - '1'; ps[id].push_back(P(x, y)); } } } V = 2; for (int i = 0; i < 5; i++){ for (auto& p : ps[i]){ is[i].push_back(V++); } } short mini = INF; int mini_id = -1; for (int i = 0; i < MAX_V; i++){ for (int j = 0; j < MAX_V; j++){ cost[i][j] = INF; } } for (int init = 0; init < 5; init++){ int nxt = (init + 1) % 5; for (int i = 0; i < ps[nxt].size(); i++){ cost[0][is[nxt][i]] = dist(start, ps[nxt][i]); } for (int i = 0; i < 3; i++){ int nnxt = (nxt + 1) % 5; for (int j = 0; j < ps[nxt].size(); j++){ for (int k = 0; k < ps[nnxt].size(); k++){ cost[is[nxt][j]][is[nnxt][k]] = dist(ps[nxt][j], ps[nnxt][k]); } } nxt = nnxt; } for (int i = 0; i < ps[nxt].size(); i++){ cost[is[nxt][i]][1] = dist(goal, ps[nxt][i]); } dijkstra(0); if (mini > d[1]){ mini = d[1]; mini_id = init; } } if (mini_id == -1) puts("NA"); else printf("%d %d\n", mini_id + 1, mini); } return 0; }
a.cc: In function 'void dijkstra(int)': a.cc:28:17: error: no matching function for call to 'min(short int&, int)' 28 | d[u] = min(d[u], d[v] + cost[v][u]); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /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:28:17: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int') 28 | d[u] = min(d[u], d[v] + cost[v][u]); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~ /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: /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:28:17: note: mismatched types 'std::initializer_list<_Tp>' and 'short int' 28 | d[u] = min(d[u], d[v] + cost[v][u]); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~
s206909927
p00215
C++
function main(){ var i = 0; while(true){ var fieldInfo = input[i].split(' '); var width = fieldInfo[0] - 0;//toInt var height = fieldInfo[1] - 0;//toInt // 0 0が入力された if(!width && !height){ break; } var start; var goal; var elem = [[],[],[],[],[]]; var c; for(var y = height; y--;){ i++;//1行進める var ni = input[i]; for(var x = width; x--;){ c = ni[x]; if(c === '.'){ // ドットが一番多いはずなので、先にひっかけてしまう }else if(c === '1' || c === '2' || c === '3' || c === '4' || c === '5'){ // 次に多いはずの属性を潰す // FIXME:判定条件は最適化できそう var e = elem[c - 1]; e[e.length] = pos(x, y); }else if(c === 'S'){ start = pos(x, y); }else{ goal = pos(x, y); } } } var INF = 1 << 27; var bestElement = -1; var distance = INF; // 属性ごとにループ var startElem = 5; for (; startElem--;) { // DPの初期化 DP[属性][同じ属性内の連番] var dp = [[],[],[],[],[]]; for(var h = 5; h--;){ var hLength = elem[h].length; dp[h].length = hLength; var initdph = dp[h]; for(; hLength--;){ initdph[hLength] = INF; } } // 最初に選んだパチモンから次に捕まえられる属性番号 var first = (startElem + 1) % 5; var firstLength = elem[first].length; var dpf = dp[first]; var elemf = elem[first]; for (var j = 0; j < firstLength; j++) { // s→e1を計算 dpf[j] = dist(start, elemf[j]); } // s->1->2->3->4->g // なので、ループは間の-> * 3分まわす for (var e = 0; e < 3; e++) { // ex->e(x+1) var now = (first + e) % 5; var next = (now + 1) % 5; var dpnw = dp[now]; var dpnx = dp[next]; var elnw = elem[now]; var elnx = elem[next]; var nowLength = elnw.length; var nextLength = elnx.length; for (var j = 0; j < nowLength; j++) { var dpnwj = dpnw[j]; var elnwj = elnw[j]; for (var k = 0; k < nextLength; k++) { dpnx[k] = min( dpnx[k], dpnwj + dist(elnwj, elnx[k])); } } } var last = (first + 3) % 5; var lastLength = elem[last].length; var dpl = dp[last]; var ell = elem[last]; for (var j = 0; j < lastLength; j++) { // e4->g var d = ((dpl[j] + dist(ell[j], goal)) << 3) + startElem; distance = min(d, distance); } } if (distance === INF) { console.log("NA"); } else { console.log(((distance & 7) + 1) + " " + (distance >> 3)); } i++; } } function dist(from, to){ // x座標とy座標の切り出し(11ビット右シフトでxを、2047(下位10ビット1)とのAND演算でyを取り出す) return abs((from >> 11) - (to >> 11)) + abs((from & 2047) - (to & 2047)); } function min(a, b){ // ビット演算で高速化 var t = a - b; return b + (t & (t >> 31)); } function pos(a, b){ // 2^10 = 1024なので、下位10ビットでy座標を、上位ビットでx座標を表す return (a << 11) + b; } function abs(a){ // ビット演算で高速化 var mask = a >> 31; return (a ^ mask) - mask; } var input = ''; process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function(chunk) { input += chunk; }); process.stdin.on('end', function() { input = input.split('\n'); main(); });
a.cc:141:9: error: empty character constant 141 | input = ''; | ^~ a.cc:144:27: warning: multi-character character constant [-Wmultichar] 144 | process.stdin.setEncoding('utf8'); | ^~~~~~ a.cc:145:18: warning: multi-character character constant [-Wmultichar] 145 | process.stdin.on('data', function(chunk) { | ^~~~~~ a.cc:148:18: warning: multi-character character constant [-Wmultichar] 148 | process.stdin.on('end', function() { | ^~~~~ a.cc:1:1: error: 'function' does not name a type; did you mean 'union'? 1 | function main(){ | ^~~~~~~~ | union a.cc:118:1: error: 'function' does not name a type; did you mean 'union'? 118 | function dist(from, to){ | ^~~~~~~~ | union a.cc:123:1: error: 'function' does not name a type; did you mean 'union'? 123 | function min(a, b){ | ^~~~~~~~ | union a.cc:129:1: error: 'function' does not name a type; did you mean 'union'? 129 | function pos(a, b){ | ^~~~~~~~ | union a.cc:134:1: error: 'function' does not name a type; did you mean 'union'? 134 | function abs(a){ | ^~~~~~~~ | union a.cc:140:1: error: 'var' does not name a type 140 | var | ^~~ a.cc:143:1: error: 'process' does not name a type 143 | process.stdin.resume(); | ^~~~~~~ a.cc:144:1: error: 'process' does not name a type 144 | process.stdin.setEncoding('utf8'); | ^~~~~~~ a.cc:145:1: error: 'process' does not name a type 145 | process.stdin.on('data', function(chunk) { | ^~~~~~~ a.cc:147:2: error: expected unqualified-id before ')' token 147 | }); | ^ a.cc:148:1: error: 'process' does not name a type 148 | process.stdin.on('end', function() { | ^~~~~~~ a.cc:151:2: error: expected unqualified-id before ')' token 151 | }); | ^
s352138888
p00215
C++
#include <iostream> #include <complex> #include <sstream> #include <string> #include <algorithm> #include <deque> #include <list> #include <map> #include <numeric> #include <queue> #include <vector> #include <set> #include <limits> #include <cstdio> #include <cctype> #include <cmath> #include <cstring> #include <cstdlib> #include <ctime> using namespace std; #define REP(i, j) for(int i = 0; i < (int)(j); ++i) #define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i) #define SORT(v) sort((v).begin(), (v).end()) #define REVERSE(v) reverse((v).begin(), (v).end()) typedef pair<int, int> P; const int L = 5; const int MAX_H = 1010; const int MAX_W = 1010; const int INF = 1e9 + 7; class C{ public: int y, x, cnt, fir, bit; C(){} C(int yy, int xx, int cc, int ff, int bb) { y = yy; x = xx; cnt = cc; fir = ff; bit = bb; } }; int W, H; int my[] = {0, 0, 1, -1}; int mx[] = {1, -1, 0, 0}; int closed[MAX_H][MAX_W][(1 << L)]; bool check(int bit, int m){ int tar = (m == 0 ? 4 : m - 1); if(bit & (1 << tar)) return true; return false; } P solve(int sy, int sx, int gy, int gx, vector< vector<int> > &v){ queue<C> open; REP(i, MAX_H) REP(j, MAX_W) REP(k, L) REP(l, (1 << L)) closed[i][j][k][l] = INF; //REP(i, L){ // open.push(C(sy, sx, 0, i, (1 << i))); // closed[sy][sx][i][(1 << i)] = 0; //} //while(!open.empty()){ // C c = open.front(); open.pop(); // REP(i, 4){ // int ny = c.y + my[i], nx = c.x + mx[i]; // if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue; // int nb = c.bit; // if(v[ny][nx] != -1 && check(c.bit, v[ny][nx])) nb |= (1 << v[ny][nx]); // if(closed[ny][nx][c.fir][nb] <= c.cnt + 1) continue; // closed[ny][nx][c.fir][nb] = c.cnt + 1; // open.push(C(ny, nx, c.cnt + 1, c.fir, nb)); // } //} P res = P(INF, INF); //REP(i, L) if(closed[gy][gx][i][(1 << L) - 1] < res.second) res = P(i + 1, closed[gy][gx][i][(1 << L) - 1]); return res; } int main() { while(cin >>W >>H && W && H){ int sy, sx, gy, gx; vector< vector<int> > v(H, vector<int>(W)); REP(i, H){ REP(j, W){ char c; cin >>c; if(c == 'S') { sy = i; sx = j; v[i][j] = -1; } else if(c == 'G') { gy = i; gx = j; v[i][j] = -1; } else if(c == '.') { v[i][j] = -1; } else { v[i][j] = c - '0' - 1; } } } P res = solve(sy, sx, gy, gx, v); if(res.first == INF) cout <<"NA" <<endl; else cout <<res.first <<" " <<res.second <<endl; } return 0; }
a.cc: In function 'P solve(int, int, int, int, std::vector<std::vector<int> >&)': a.cc:51:73: error: invalid types 'int[int]' for array subscript 51 | REP(i, MAX_H) REP(j, MAX_W) REP(k, L) REP(l, (1 << L)) closed[i][j][k][l] = INF; | ^
s952025027
p00215
C++
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> #include<list> #include<cctype> #include<climits> using namespace std; int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; //----?????°????????????????????????????????£?????????????????? template <class T> class myQueue { public: T *data; int head, tail; int max_size; myQueue() {}; myQueue(int size); T &dequeue(); void enqueue(T &city); }; template <class T> myQueue<T>::myQueue(int size) { data = new T[size]; head = tail = 0; max_size = size; } template <class T> T &myQueue<T>::dequeue() { if (head == max_size) head = 0; return data[head++]; } template <class T> void myQueue<T>::enqueue(T &c) { if (tail == max_size) tail = 0; data[tail++] = c; } //------------------------------------- struct Data { int x, y, dist, state; Data() {} Data(int _x, int _y, int _dist, int _state) { x = _x; y = _y; dist = _dist; state = _state; } }; char fld[1000][1000]; bool isUsed[5][1000][1000]; inline int GetNext(int n) { return (n == 4) ? 0 : n + 1; } inline int GetPrev(int n) { return (n == 0) ? 4 : n - 1; } signed main() { int W, H; while (cin >> W >> H, W || H) { int sx, sy, gx, gy; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { scanf(" %c", &fld[i][j]); if (fld[i][j] == 'S') { sx = j; sy = i; } else if (fld[i][j] == 'G') { gx = j; gy = i; } } } int mi = INT_MAX / 2, ans; for (int i = 0; i < 5; i++) { myQueue<Data> q(5 * W * H); Data qf; q.enqueue(Data(sx, sy, 0, i)); fill_n((bool*)isUsed, 5 * 1000 * 1000, false); isUsed[i][sy][sx] = true; while (q.head < q.tail) { qf = q.dequeue(); if (qf.x == gx && qf.y == gy && qf.state == GetPrev(qf.state)) { if (mi > qf.dist) { mi = qf.dist; ans = i; break; } } for (int j = 0; j < 4; j++) { int nx = qf.x + dx[j]; int ny = qf.y + dy[j]; if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue; int state = qf.state; if (isdigit(fld[ny][nx]) && fld[ny][nx] - '1' != i && fld[ny][nx] - '1' == GetNext(state)) { state = GetNext(state); } if (isUsed[state][ny][nx]) continue; isUsed[state][ny][nx] = true; q.enqueue(Data(nx, ny, qf.dist + 1, state)); } } } if (mi == INT_MAX / 2) puts("NA"); else printf("%d %d\n", ans, mi); } return 0; }
a.cc: In function 'int main()': a.cc:106:35: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data' 106 | q.enqueue(Data(sx, sy, 0, i)); | ^~~~~~~~~~~~~~~~~~ a.cc:44:29: note: initializing argument 1 of 'void myQueue<T>::enqueue(T&) [with T = Data]' 44 | void myQueue<T>::enqueue(T &c) { | ~~~^ a.cc:133:51: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data' 133 | q.enqueue(Data(nx, ny, qf.dist + 1, state)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:44:29: note: initializing argument 1 of 'void myQueue<T>::enqueue(T&) [with T = Data]' 44 | void myQueue<T>::enqueue(T &c) { | ~~~^
s436756860
p00215
C++
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> #include<list> #include<cctype> #include<climits> using namespace std; int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; //----------------Pakuri Code------------------------ template <class T> class myQueue { public: T *data; int head, tail; int max_size; myQueue() {}; myQueue(int size); T &dequeue(); void enqueue(T &city); }; template <class T> myQueue<T>::myQueue(int size) { data = new T[size]; head = tail = 0; max_size = size; } template <class T> T &myQueue<T>::dequeue() { if (head == max_size) head = 0; return data[head++]; } template <class T> void myQueue<T>::enqueue(T &c) { if (tail == max_size) tail = 0; data[tail++] = c; } //------------------------------------- struct Data { int x, y, dist, state; Data() {} Data(int _x, int _y, int _dist, int _state) { x = _x; y = _y; dist = _dist; state = _state; } }; char fld[1000][1000]; bool isUsed[5][1000][1000]; inline int GetNext(int n) { return (n == 4) ? 0 : n + 1; } inline int GetPrev(int n) { return (n == 0) ? 4 : n - 1; } signed main() { int W, H; while (cin >> W >> H, W || H) { int sx, sy, gx, gy; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { scanf(" %c", &fld[i][j]); if (fld[i][j] == 'S') { sx = j; sy = i; } else if (fld[i][j] == 'G') { gx = j; gy = i; } } } int mi = INT_MAX / 2, ans; for (int i = 0; i < 5; i++) { myQueue<Data> q(5 * W * H); Data qf; q.enqueue(Data(sx, sy, 0, i)); fill_n((bool*)isUsed, 5 * 1000 * 1000, false); isUsed[i][sy][sx] = true; while (q.head < q.tail) { qf = q.dequeue(); if (qf.x == gx && qf.y == gy && qf.state == GetPrev(qf.state)) { if (mi > qf.dist) { mi = qf.dist; ans = i; break; } } for (int j = 0; j < 4; j++) { int nx = qf.x + dx[j]; int ny = qf.y + dy[j]; if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue; int state = qf.state; if (isdigit(fld[ny][nx]) && fld[ny][nx] - '1' != i && fld[ny][nx] - '1' == GetNext(state)) { state = GetNext(state); } if (isUsed[state][ny][nx]) continue; isUsed[state][ny][nx] = true; q.enqueue(Data(nx, ny, qf.dist + 1, state)); } } } if (mi == INT_MAX / 2) puts("NA"); else printf("%d %d\n", ans, mi); } return 0; }
a.cc: In function 'int main()': a.cc:106:35: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data' 106 | q.enqueue(Data(sx, sy, 0, i)); | ^~~~~~~~~~~~~~~~~~ a.cc:44:29: note: initializing argument 1 of 'void myQueue<T>::enqueue(T&) [with T = Data]' 44 | void myQueue<T>::enqueue(T &c) { | ~~~^ a.cc:133:51: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data' 133 | q.enqueue(Data(nx, ny, qf.dist + 1, state)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:44:29: note: initializing argument 1 of 'void myQueue<T>::enqueue(T&) [with T = Data]' 44 | void myQueue<T>::enqueue(T &c) { | ~~~^
s419227637
p00215
C++
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> #include<list> #include<cctype> #include<climits> using namespace std; int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; struct Data { int x, y, dist, state; Data() {} Data(int _x, int _y, int _dist, int _state) { x = _x; y = _y; dist = _dist; state = _state; } }; struct MockQueue { Data *data; int head, tail; MockQueue(int size) { data = new Data[size]; head = tail = 0; } void Enqueue(Data &d) { data[tail++] = d; } Data Dequeue() { return data[head++]; } }; char fld[1000][1000]; bool isUsed[5][1000][1000]; inline int GetNext(int n) { return (n == 4) ? 0 : n + 1; } inline int GetPrev(int n) { return (n == 0) ? 4 : n - 1; } signed main() { int W, H; while (cin >> W >> H, W || H) { int sx, sy, gx, gy; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { scanf(" %c", &fld[i][j]); if (fld[i][j] == 'S') { sx = j; sy = i; } else if (fld[i][j] == 'G') { gx = j; gy = i; } } } int mi = INT_MAX / 2, ans; for (int i = 0; i < 5; i++) { MockQueue q(20 * W * H); Data qf; q.Enqueue(Data(sx, sy, 0, i)); fill_n((bool*)isUsed, 5 * 1000 * 1000, false); isUsed[i][sy][sx] = true; while (q.head != q.tail) { qf = q.Dequeue(); if (qf.x == gx && qf.y == gy && qf.state == GetPrev(i)) { if (mi > qf.dist) { mi = qf.dist; ans = i; break; } } for (int j = 0; j < 4; j++) { int nx = qf.x + dx[j]; int ny = qf.y + dy[j]; if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue; int state = qf.state; if (isUsed[state][ny][nx]) continue; isUsed[state][ny][nx] = true; if (isdigit(fld[ny][nx]) && fld[ny][nx] - '1' != i && fld[ny][nx] - '1' == GetNext(state)) { state = GetNext(state); } q.Enqueue(Data(nx, ny, qf.dist + 1, state)); } } } if (mi == INT_MAX / 2) puts("NA"); else printf("%d %d\n", ans, mi); } return 0; }
a.cc: In function 'int main()': a.cc:93:35: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data' 93 | q.Enqueue(Data(sx, sy, 0, i)); | ^~~~~~~~~~~~~~~~~~ a.cc:39:28: note: initializing argument 1 of 'void MockQueue::Enqueue(Data&)' 39 | void Enqueue(Data &d) | ~~~~~~^ a.cc:120:51: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data' 120 | q.Enqueue(Data(nx, ny, qf.dist + 1, state)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:39:28: note: initializing argument 1 of 'void MockQueue::Enqueue(Data&)' 39 | void Enqueue(Data &d) | ~~~~~~^
s318975668
p00215
C++
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> #include<list> #include<cctype> #include<climits> using namespace std; int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; struct Data { int x, y, dist, state; Data() {} Data(int _x, int _y, int _dist, int _state) { x = _x; y = _y; dist = _dist; state = _state; } }; class MockQueue { public: Data *data; int head, tail; MockQueue(int size) { data = new Data[size]; head = tail = 0; } void Enqueue(Data &d) { data[tail++] = d; } Data Dequeue() { return data[head++]; } }; char fld[1000][1000]; bool isUsed[5][1000][1000]; inline int GetNext(int n) { return (n == 4) ? 0 : n + 1; } inline int GetPrev(int n) { return (n == 0) ? 4 : n - 1; } signed main() { int W, H; while (cin >> W >> H, W || H) { int sx, sy, gx, gy; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { scanf(" %c", &fld[i][j]); if (fld[i][j] == 'S') { sx = j; sy = i; } else if (fld[i][j] == 'G') { gx = j; gy = i; } } } int mi = INT_MAX / 2, ans; for (int i = 0; i < 5; i++) { MockQueue q(20 * W * H); Data qf; q.Enqueue(Data(sx, sy, 0, i)); fill_n((bool*)isUsed, 5 * 1000 * 1000, false); isUsed[i][sy][sx] = true; while (q.head != q.tail) { qf = q.Dequeue(); if (qf.x == gx && qf.y == gy && qf.state == GetPrev(i)) { if (mi > qf.dist) { mi = qf.dist; ans = i; break; } } for (int j = 0; j < 4; j++) { int nx = qf.x + dx[j]; int ny = qf.y + dy[j]; if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue; int state = qf.state; if (isUsed[state][ny][nx]) continue; isUsed[state][ny][nx] = true; if (isdigit(fld[ny][nx]) && fld[ny][nx] - '1' != i && fld[ny][nx] - '1' == GetNext(state)) { state = GetNext(state); } q.Enqueue(Data(nx, ny, qf.dist + 1, state)); } } } if (mi == INT_MAX / 2) puts("NA"); else printf("%d %d\n", ans, mi); } return 0; }
a.cc: In function 'int main()': a.cc:94:35: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data' 94 | q.Enqueue(Data(sx, sy, 0, i)); | ^~~~~~~~~~~~~~~~~~ a.cc:40:28: note: initializing argument 1 of 'void MockQueue::Enqueue(Data&)' 40 | void Enqueue(Data &d) | ~~~~~~^ a.cc:121:51: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data' 121 | q.Enqueue(Data(nx, ny, qf.dist + 1, state)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:40:28: note: initializing argument 1 of 'void MockQueue::Enqueue(Data&)' 40 | void Enqueue(Data &d) | ~~~~~~^
s749956757
p00215
C++
#include <iostream> #include <vector> #include <cctype> #include <queue> #include <functional> #include <cmath> #include <algorithm> constexpr int MAX = 1000, INF = INT_MAX; struct edge { int toX_, toY_; edge() = default; edge(int x, int y) : toX_(x), toY_(y) {} }; struct Node { int cost_, x_, y_, num_, cnt_; Node() = default; Node(int cost, int x, int y, int num, int cnt) : cost_(cost), x_(x), y_(y), num_(num), cnt_(cnt) {} bool operator<(const Node& rhs) const { return (cost_ == rhs.cost_) ? cnt_ < rhs.cnt_ : cost_ < rhs.cost_; } bool operator > (const Node& rhs) const { return (cost_ == rhs.cost_ ? cnt_ > rhs.cnt_ : cost_ > rhs.cost_); } }; int w, h; int sx, sy, gx, gy; std::vector<edge> G[5]; int d[MAX][MAX]; int dijkstra(int num) { for (int j = 0; j < h; ++j) { for (int k = 0; k < w; ++k) d[j][k] = INF; } std::priority_queue<Node, std::vector<Node>,std::greater<Node>> que; d[sy][sx] = 0; que.emplace(0, sx, sy, num, 1); while (!que.empty()) { Node node = que.top(); que.pop(); if (node.cost_ > d[node.y_][node.x_]) continue; if (node.cnt_ == 5) return d[node.y_][node.x_] + abs(gx - node.x_) + abs(gy - node.y_); edge e; for (int i = 0; i < G[node.num_].size(); ++i) { e = G[node.num_][i]; if (d[e.toY_][e.toX_] > d[node.y_][node.x_] + abs(e.toX_ - node.x_) + abs(e.toY_ - node.y_)) { d[e.toY_][e.toX_] = d[node.y_][node.x_] + abs(e.toX_ - node.x_) + abs(e.toY_ - node.y_); que.emplace(d[e.toY_][e.toX_], e.toX_, e.toY_, (node.num_ + 1) % 5, node.cnt_ + 1); } } } return -1; } int main() { while (1) { std::cin >> w >> h; if (w + h == 0) break; for (int i = 0; i < 5; ++i) G[i].clear(); char ch; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { std::cin >> ch; if (ch == 'S') { sx = j; sy = i; } else if (ch == 'G') { gx = j; gy = i; } if (std::isdigit(ch)) { int num = atoi(&ch); --num; G[(num + 4) % 5].emplace_back(j, i); } } } int ans = INF, v, res; for (int i = 0; i < 5; ++i) { res = dijkstra(i); if (res != -1 && ans > res) { ans = res; v = i; } } if (ans == INF) std::cout << "NA" << std::endl; else std::cout << v + 1 << ' ' << ans << std::endl; } return 0; }
a.cc:9:33: error: 'INT_MAX' was not declared in this scope 9 | constexpr int MAX = 1000, INF = INT_MAX; | ^~~~~~~ a.cc:8:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 7 | #include <algorithm> +++ |+#include <climits> 8 |
s345068116
p00215
C++
#include <iostream> #include <vector> #include <cctype> #include <queue> #include <functional> #include <cmath> #include <algorithm> constexpr int MAX = 1000, INF = INT_MAX; struct edge { int toX_, toY_; edge() = default; edge(int x, int y) : toX_(x), toY_(y) {} }; struct Node { int cost_, x_, y_, num_, cnt_; Node() = default; Node(int cost, int x, int y, int num, int cnt) : cost_(cost), x_(x), y_(y), num_(num), cnt_(cnt) {} bool operator<(const Node& rhs) const { return (cost_ == rhs.cost_) ? cnt_ < rhs.cnt_ : cost_ < rhs.cost_; } bool operator > (const Node& rhs) const { return (cost_ == rhs.cost_ ? cnt_ > rhs.cnt_ : cost_ > rhs.cost_); } }; int w, h; int sx, sy, gx, gy; std::vector<edge> G[5]; int d[MAX][MAX]; int dijkstra(int num) { for (int j = 0; j < h; ++j) { for (int k = 0; k < w; ++k) d[j][k] = INF; } std::priority_queue<Node, std::vector<Node>,std::greater<Node>> que; d[sy][sx] = 0; que.emplace(0, sx, sy, num, 1); while (!que.empty()) { Node node = que.top(); que.pop(); if (node.cost_ > d[node.y_][node.x_]) continue; if (node.cnt_ == 5) return d[node.y_][node.x_] + abs(gx - node.x_) + abs(gy - node.y_); edge e; for (int i = 0; i < G[node.num_].size(); ++i) { e = G[node.num_][i]; if (d[e.toY_][e.toX_] > d[node.y_][node.x_] + abs(e.toX_ - node.x_) + abs(e.toY_ - node.y_)) { d[e.toY_][e.toX_] = d[node.y_][node.x_] + abs(e.toX_ - node.x_) + abs(e.toY_ - node.y_); que.emplace(d[e.toY_][e.toX_], e.toX_, e.toY_, (node.num_ + 1) % 5, node.cnt_ + 1); } } } return -1; } int main() { while (1) { std::cin >> w >> h; if (w + h == 0) break; for (int i = 0; i < 5; ++i) G[i].clear(); char ch; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { std::cin >> ch; if (ch == 'S') { sx = j; sy = i; } else if (ch == 'G') { gx = j; gy = i; } if (std::isdigit(ch)) { int num = atoi(&ch); --num; G[(num + 4) % 5].emplace_back(j, i); } } } int ans = INF, v, res; for (int i = 0; i < 5; ++i) { res = dijkstra(i); if (res != -1 && ans > res) { ans = res; v = i; } } if (ans == INF) std::cout << "NA" << std::endl; else std::cout << v + 1 << ' ' << ans << std::endl; } return 0; }
a.cc:9:33: error: 'INT_MAX' was not declared in this scope 9 | constexpr int MAX = 1000, INF = INT_MAX; | ^~~~~~~ a.cc:8:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 7 | #include <algorithm> +++ |+#include <climits> 8 |
s227266673
p00215
C++
#include <iostream> #include <math.h> char map[1000 + 2][1000 + 2]; int gx, gy; int size_x, size_y; int ans; int ans_el; using namespace std; int calc(int x, int y, int get, int have, int dist) { if (have == get){ if (dist + abs(x - gx) + abs(y - gy) < ans){ ans = dist + abs(x - gx) + abs(y - gy); ans_el = have; } return (1); } if (dist >= ans){ return (0); } for (int mx = 1; mx <= size_x; mx++){ for (int my = 1; my <= size_y; my++){ if (map[mx][my] - '0' - 1 == get){ calc(mx, my, (get + 1) % 5, have, dist + abs(x - mx) + abs(y - my)); } } } return (0); } int main(void) { int sx, sy; int have; int get; while (1){ cin >> size_x >> size_y; if (size_x == 0 && size_y == 0)break; memset(map, -1, size_x * size_y); for (int y = 1; y <= size_y; y++){ ans = 10000000; ans_el = -1; char str[1001]; cin >> str; for (int x = 1; x <= size_x; x++){ if (str[x - 1] == 'S'){ sx = x; sy = y; } if (str[x - 1] == 'G'){ gx = x; gy = y; } map[x][y] = str[x - 1]; } } for (int i = 0; i < 5; i++){ have = i; get = (i + 1) % 5; calc(sx, sy, get, have, 0); } if (ans_el == -1){ cout << "NA" << endl; } else { cout << ans_el + 1 << ' ' << ans << endl; } } return (0); }
a.cc: In function 'int main()': a.cc:46:9: error: 'memset' was not declared in this scope 46 | memset(map, -1, size_x * size_y); | ^~~~~~ a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 2 | #include <math.h> +++ |+#include <cstring> 3 |
s795523066
p00215
C++
#include<cstdio> #include<vector> #define mp make_pair #define pb push_back using namespace std; typedef pair<int,int> pii; char field[1000][1001]; int memo[1000][5]; int dis(const pii &a,const pii &b){ return abs(a.first-b.first)+abs(a.second-b.second); } int main(){ for(int w,h;scanf("%d%d",&w,&h),w;){ pii s,g; vector<pii> pach[5]; for(int i=0;i<h;i++){ static char field[1001]; scanf("%s",field); for(int j=0;j<w;j++){ if (field[j]=='S') s=mp(i,j); else if(field[j]=='G') g=mp(i,j); else if(field[j]=='1') pach[field[j]-'1'].pb(mp(i,j)); else if(field[j]=='2') pach[field[j]-'1'].pb(mp(i,j)); else if(field[j]=='3') pach[field[j]-'1'].pb(mp(i,j)); else if(field[j]=='4') pach[field[j]-'1'].pb(mp(i,j)); else if(field[j]=='5') pach[field[j]-'1'].pb(mp(i,j)); } } int ans=1<<30,bestpartner; for(int partner=0;partner<5;partner++){ int bef=partner,next=(partner+1)%5; for(int i=0;i<pach[next].size();i++){ memo[i][next]=dis(s,pach[next][i]); } bef=next; next=(next+1)%5; for(int k=1;k<4;k++){ for(int i=0;i<pach[next].size();i++){ memo[i][next]=1<<30; for(int j=0;j<pach[bef].size();j++){ memo[i][next]=min(memo[i][next], memo[j][bef]+dis(pach[bef][j],pach[next][i])); } } bef=next; next=(next+1)%5; } for(int j=0;j<pach[bef].size();j++){ int tmp=memo[j][bef]+dis(pach[bef][j],g); if(tmp<ans){ ans=tmp; bestpartner=partner; } } } if(ans==(1<<30)) puts("NA"); else printf("%d %d\n",bestpartner+1,ans); } return 0; }
a.cc: In function 'int dis(const pii&, const pii&)': a.cc:15:16: error: 'abs' was not declared in this scope 15 | return abs(a.first-b.first)+abs(a.second-b.second); | ^~~
s764308797
p00215
C++
#include<cstdio> #include<vector> #define mp make_pair #define pb push_back using namespace std; typedef pair<int,int> pii; int memo[1000][5]; int dis(const pii &a,const pii &b){ return abs(a.first-b.first)+abs(a.second-b.second); } int main(){ for(int w,h;scanf("%d%d",&w,&h),w;){ pii s,g; vector<pii> pach[5]; for(int i=0;i<h;i++){ static char field[1001]; scanf("%s",field); for(int j=0;j<w;j++){ if (field[j]=='S') s=mp(i,j); else if(field[j]=='G') g=mp(i,j); else if(field[j]=='1') pach[field[j]-'1'].pb(mp(i,j)); else if(field[j]=='2') pach[field[j]-'1'].pb(mp(i,j)); else if(field[j]=='3') pach[field[j]-'1'].pb(mp(i,j)); else if(field[j]=='4') pach[field[j]-'1'].pb(mp(i,j)); else if(field[j]=='5') pach[field[j]-'1'].pb(mp(i,j)); } } int ans=1<<30,bestpartner; for(int partner=0;partner<5;partner++){ int bef=partner,next=(partner+1)%5; for(int i=0;i<pach[next].size();i++){ memo[i][next]=dis(s,pach[next][i]); } bef=next; next=(next+1)%5; for(int k=1;k<4;k++){ for(int i=0;i<pach[next].size();i++){ memo[i][next]=1<<30; for(int j=0;j<pach[bef].size();j++){ memo[i][next]=min(memo[i][next], memo[j][bef]+dis(pach[bef][j],pach[next][i])); } } bef=next; next=(next+1)%5; } for(int j=0;j<pach[bef].size();j++){ int tmp=memo[j][bef]+dis(pach[bef][j],g); if(tmp<ans){ ans=tmp; bestpartner=partner; } } } if(ans==(1<<30)) puts("NA"); else printf("%d %d\n",bestpartner+1,ans); } return 0; }
a.cc: In function 'int dis(const pii&, const pii&)': a.cc:14:16: error: 'abs' was not declared in this scope 14 | return abs(a.first-b.first)+abs(a.second-b.second); | ^~~
s970320985
p00215
C++
#include <iostream> #include <cstdlib> #include <vector> using namespace std; struct P{int x,y,cost;}; #define INF (1<<25) #define rep(i,n) for(int i=0; i<n ;i++) int dist(P a,P b){ return abs(a.x-b.x) + abs(a.y-b.y); } int main(){ int w,h; while(cin >> w >> h , w) { vector<P> data[5]; P start , goal ; start.cost = 0 , goal.cost = 0; rep(i,h)rep(j,w){ char c; cin >> c; if(c != '.'){ if(c == 'S')start.x = j , start.y = i; else if(c == 'G')goal.x = j , goal.y = i; else P t = {j,i,0} , data[c-'1'].push_back(t); } } int ret = INF , num ; P dp[5][1000]; rep(lp,5){ // start rep(i,5)rep(j,1000){dp[i][j].cost = INF;} int so = (lp+1)%5; rep(i,data[so].size()){ dp[so][i] = data[so][i]; dp[so][i].cost = dist(data[so][i],start); } rep(Z,3){ // remain int z = (lp+Z+2)%5; int prev = (z+4)%5; rep(i,data[prev].size()){ // prev rep(j,data[z].size()){ //cur int cost = dp[prev][i].cost + dist(dp[prev][i],data[z][j]); if(dp[z][j].cost > cost){ dp[z][j] = data[z][j] , dp[z][j].cost = cost; } } } } rep(i,data[(lp+4)%5].size() ){ int kCost = dp[(lp+4)%5][i].cost + dist(dp[(lp+4)%5][i],goal); if( kCost < ret){ ret = kCost , num = lp+1; } } } if(ret == INF)cout << "NA" << endl; else cout << num << " " << ret << endl; } }
a.cc: In function 'int main()': a.cc:26:65: error: expected initializer before '.' token 26 | else P t = {j,i,0} , data[c-'1'].push_back(t); | ^
s923761496
p00215
C++
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <complex> using namespace std; #define INF 1 << 16 typedef complex<int> P; int abs(int n) { return n < 0 ? -n : n; } int main() { int W, H; while (cin >> W >> H, W || H) { vector<P> v; vector<int> type; vector< vector<int> > m(7); for (int y = 0; y < H; ++y) { string str; cin >> str; for (int x = 0; x < W; ++x) { if (str[x] == '.') continue; v.push_back( P(x, y) ); if (str[x] == 'S') type.push_back( 5 ); else if (str[x] == 'G') type.push_back( 6 ); else if (str[x] != '.') type.push_back( str[x] - '1' ); m[type[type.size()-1]].push_back(v.size()-1); } } int f = false; for (int i = 0; i < 5; ++i) if ( !m[i].size() ) f = true; if (f) { cout << "NA" << endl; continue; } vector< vector<int> > cost(v.size(), vector<int>(v.size(), INF)); for (int i = 0; i < v.size(); ++i) for (int j = 0; j < v.size(); ++j) cost[i][j] = ; pair<int, int> ans = pair<int, int>(0, INF); for (int kind = 0; kind < 5; ++kind) { vector<int> len(v.size(), INF); vector<int> types; types.push_back(5); for (int i = 0; i < 4; ++i) types.push_back( (kind + i + 1) % 5 ); types.push_back(6); len[m[5][0]] = 0; for (int i = 0; i < 5; ++i) { int now = types[i], next = types[i+1]; for (int j = 0; j < m[next].size(); ++j) for (int k = 0; k < m[now].size(); ++k) if (len[m[next][j]] > len[m[now][k]] + abs(v[m[now][k]].real() - v[m[next][j]].real()) + abs(v[m[now][k]].imag() - v[m[next][j]].imag())) len[m[next][j]] = len[m[now][k]] + abs(v[m[now][k]].real() - v[m[next][j]].real()) + abs(v[m[now][k]].imag() - v[m[next][j]].imag()); } if (len[m[6][0]] < ans.second) ans = pair<int, int>(kind+1, len[m[6][0]]); } cout << ans.first << " " << ans.second << endl; } }
a.cc: In function 'int main()': a.cc:51:46: error: expected primary-expression before ';' token 51 | cost[i][j] = ; | ^
s477058868
p00215
C++
#include <cstdio> #include <vector> #include <utility> #include <queue> #include <algorithm> using namespace std; #define inf (1<<27) #define abs(n) ((n)>=0?(n):-(n)) #define next(p) ((p)%5+1) typedef pair<int,int> P; typedef pair<int,P> P2; int d[6][1000]; int o[6]; int dist(P &a,P &b) {return abs(a.first-b.first)+abs(a.second-b.second);} int main() { int x,y; while(scanf("%d%d",&x,&y),x) { vector<P> p[7]; for(int j=0;j<y;j++) { getchar(); for(int i=0;i<x;i++) { char ch=getchar(); if(ch=='S')p[0].push_back(P(i,j)); if(ch=='G')p[6].push_back(P(i,j)); if(ch!='.')p[ch-'0'].push_back(P(i,j)); } } bool na=false; for(int i=0;i<7;i++)if(!p[i].size())na=true; if(na) {printf("NA\n");continue;} o[0]=0;o[5]=6; int ans=inf; for(int m=1;m<=5;m++) { for(int t=next(m),i=1;i<=4;i++,t=next(t))o[i]=t; fill(d[0],d[0]+6*1000,inf); d[0][0]=0; priority_queue<P,vector<P2>,greater<P2>> que; que.push(P2(0,P(0,0))); while(!que.empty()) { P2 p2=que.top();que.pop(); if(d[p2.second.first][p2.second.second]<p2.first)continue; if((p2.second.first+1)>=6)continue; for(int i=0;i<p[o[p2.second.first+1]].size();i++) { if(d[p2.second.first+1][i]>p2.first+dist(p[o[p2.second.first]][p2.second.second],p[o[p2.second.first+1]][i])) { d[p2.second.first+1][i]=p2.first+dist(p[o[p2.second.first]][p2.second.second],p[o[p2.second.first+1]][i]); que.push(P2(p2.first+dist(p[o[p2.second.first]][p2.second.second],p[o[p2.second.first+1]][i]),P(p2.second.first+1,i))); } } } if(ans>d[5][0]) ans=d[5][0]; } printf("%d\n",ans); } }
In file included from /usr/include/c++/14/queue:66, from a.cc:4: /usr/include/c++/14/bits/stl_queue.h: In instantiation of 'class std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, std::pair<int, int> > >, std::greater<std::pair<int, std::pair<int, int> > > >': a.cc:37:45: required from here 37 | priority_queue<P,vector<P2>,greater<P2>> que; | ^~~ /usr/include/c++/14/bits/stl_queue.h:520:67: error: static assertion failed: value_type must be the same as the underlying container 520 | static_assert(is_same<_Tp, typename _Sequence::value_type>::value, | ^~~~~ /usr/include/c++/14/bits/stl_queue.h:520:67: note: 'std::integral_constant<bool, false>::value' evaluates to false
s740918407
p00215
C++
//include //------------------------------------------ #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <queue> using namespace std; //conversion //------------------------------------------ inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} //math //------------------------------------------- template<class T> inline T sqr(T x) {return x*x;} //container util //------------------------------------------ #define ALL(a) &#160;(a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) &#160;FOR(i,0,n) //IO //------------------------------------------ #define LF(x) cout << (x) << endl; #define LFA(a, n) cout << a[0]; FOR(itr, 1, n) {cout << " " << a[itr];} cout << endl; #define LFP(x, w) cout << setprecision((w)); cout << setiosflags(ios::fixed); cout << (x) << endl; //constant //-------------------------------------------- const double EPS = 1e-10; const double PI &#160;= acos(-1.0); const int INF = (int)1e9; const int dx[4]={0,1,0,-1}; const int dy[4]={1,0,-1,0}; //clear memory #define CLR(a) memset((a), 0 ,sizeof(a)) //配列関係(二次配列のときなどに使える) #define lengthof(x) (sizeof(x) / sizeof(*(x))) #define SYOKI_C(s,a) fill((char*)s, (char*)(s + lengthof(s)), a) &#160; #define SYOKI_I(s,a) fill((int*)s, (int*)(s + lengthof(s)), a) &#160; #define SYOKI_D(s,a) fill((double*)s, (double*)(s + lengthof(s)), a)&#160; #define COUNT_I(s,a) count((int*)s, (int*)(s + lengthof(s)), a) #define COUNT_C(s,a) count((char*)s, (char*)(s + lengthof(s)), a) int const MAX=1000; int kyori(pair<int ,int> a, pair<int ,int> b){ return abs(a.first-b.first)+abs(a.second-b.second); } int main(int argc, char const *argv[]) { vector<int> dp[5]; vector<pair<int ,int > > p[5]; int w,h; char c; pair< int ,int >ss; pair< int ,int >gg; int ans; int ansn; while(1){ cin>>w>>h; vector<int> dp[5]; vector<pair<int ,int > > p[5]; if(w+h==0) break; for(int i1=0;i1<h;i1++){ for(int i2=0;i2<w;i2++){ cin>>c; if('1'<=c && c<='5'){ p[c-'1'].PB(MP(i2,i1)); //cout<<c-'1'<<" &#160;"<<i2<<" "<<i1<<endl; } else if(c=='S'){ ss.first=i2; ss.second=i1; } else if(c=='G'){ gg.first=i2; gg.second=i1; } } } ans=INF; REP(i1,5){ REP(i3,5){ dp[i3].clear(); dp[i3].resize(SZ(p[i3])); //cout<<dp[i3].size()<<endl; REP(i2,SZ(p[i3])){ dp[i3][i2]=INF; } } //スタートからの距離 /*REP(i2,SZ(p[i1])){ dp[i1][i2]=0; }*/ FOR(i3,i1+1,i1+5){ int temp=i3%5; REP(i4,SZ(p[temp])){//目的 if(i3==(i1+1)){ dp[temp][i4]=kyori(ss, p[temp][i4]); } else { REP(i5,SZ(p[(i3-1)%5])){//出発 dp[temp][i4]=min(dp[temp][i4],dp[(i3-1)%5][i5]+kyori(p[(i3-1)%5][i5],p[temp][i4])); } } } } /*for(int i5=0;i5<5;i5++){ for(int i3=0;i3<dp[i5].size();i3++){ cout<<i5<<":"<<dp[i5][i3]<<" &#160;"; } cout<<endl; }*/ int temp2=(i1+4)%5; REP(i3,SZ( p[temp2] )){ if(ans>(dp[temp2][i3] +kyori(gg, p[temp2][i3]))){ ans=dp[temp2][i3] +kyori(gg, p[temp2][i3]); ansn=i1+1; } } } if(ans!=INF){ cout<<ansn<<" "<<ans<<endl; } else{ cout<<"NA"<<endl; } } return 0; }
a.cc:59:14: error: '#' is not followed by a macro parameter 59 | #define ALL(a) &#160;(a).begin(),(a).end() | ^ a.cc:74:16: error: '#' is not followed by a macro parameter 74 | #define REP(i,n) &#160;FOR(i,0,n) | ^ a.cc:95:18: error: stray '#' in program 95 | const double PI &#160;= acos(-1.0); | ^ a.cc:123:20: error: '#' is not followed by a macro parameter 123 | #define SYOKI_C(s,a) fill((char*)s, (char*)(s + lengthof(s)), a) &#160; | ^ a.cc:124:20: error: '#' is not followed by a macro parameter 124 | #define SYOKI_I(s,a) fill((int*)s, (int*)(s + lengthof(s)), a) &#160; | ^ a.cc:125:20: error: '#' is not followed by a macro parameter 125 | #define SYOKI_D(s,a) fill((double*)s, (double*)(s + lengthof(s)), a)&#160; | ^ a.cc:95:17: error: expected initializer before '&' token 95 | const double PI &#160;= acos(-1.0); | ^ a.cc:95:23: error: expected unqualified-id before '=' token 95 | const double PI &#160;= acos(-1.0); | ^ a.cc: In function 'int main(int, const char**)': a.cc:210:21: error: 'i1' was not declared in this scope; did you mean 'y1'? 210 | REP(i1,5){ | ^~ | y1 a.cc:210:17: error: 'REP' was not declared in this scope 210 | REP(i1,5){ | ^~~
s668085106
p00215
C++
#include<iostream> #include<vector> #include<map> #include<algorithm> #include<cstring> #define INF 1<<28 using namespace std; int sx, sy, gx, gy; typedef pair < int, int > P; vector < P > p[5]; int memo[5][5][1111]; int a, b; int solve(int k, int t, int q){ if(k == 4) return abs(p[t][q].F-gx) + abs(p[t][q].S-gy); if(memo[k][t][q]) return memo[k][t][q]; int ans = INF, d = (t+1)%5, s; for(int i=0;i<p[d].size();i++){ if(!k) s = abs(sx-p[d][i].first) + abs(sy-p[d][i].second); else s = abs(p[t][q].F-p[d][i].first) + abs(p[t][q].S-p[d][i].second); ans = min(ans, solve(k+1, d, i) + s); } return memo[k][t][q] = ans; } int main(){ int w,h; char c; while(true){ cin >> w >> h; if(!w && !h) break; for(int i=0;i<5;i++) p[i].clear(); for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin >> c; if(c == 'S') sx = j, sy = i; if(c == 'G') gx = j, gy = i; else if(c != '.') p[c-'1'].push_back(P(j,i)); } } b = INF; for(int i=0;i<5;i++){ memset(memo, 0, sizeof(memo)); if(b > solve(0,i,0)) a = i, b = solve(0,i,0); } if(b == INF) cout << "NA\n"; else cout << a+1 << " " << b << endl; } }
a.cc: In function 'int solve(int, int, int)': a.cc:17:33: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'F' 17 | if(k == 4) return abs(p[t][q].F-gx) + abs(p[t][q].S-gy); | ^ a.cc:17:53: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'S' 17 | if(k == 4) return abs(p[t][q].F-gx) + abs(p[t][q].S-gy); | ^ a.cc:23:26: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'F' 23 | else s = abs(p[t][q].F-p[d][i].first) + abs(p[t][q].S-p[d][i].second); | ^ a.cc:23:57: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'S' 23 | else s = abs(p[t][q].F-p[d][i].first) + abs(p[t][q].S-p[d][i].second); | ^
s659511033
p00216
Java
import java.util.Scanner; public class P01{ public P01(){ Scanner scan = new Scanner(System.in) for(int w; scan.hasNextInt() && w >= 0;){ System.out.println( 4280-getCost(w)); } } public int getCost(int w){ int cost = 1150; // ?¬¬????????? for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; // ?¬¬????????? else if ( 30 < i ) cost += 160; // ?¬¬????????? else cost += 140; // ?¬¬????????? } return cost; } public static void main(String[] args){ P01 p01 = new P01(); } }
Main.java:5: error: ';' expected Scanner scan = new Scanner(System.in) ^ 1 error
s628277966
p00216
Java
import java.util.Scanner; public class P01{ public P01(){ Scanner scan = new Scanner(System.in) for(int w; scan.hasNextInt() && w >= 0;){ System.out.println( 4280-getCost(w)); } } public int getCost(int w){ int cost = 1150; // ?¬¬????????? for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; // ?¬¬????????? else if ( 30 < i ) cost += 160; // ?¬¬????????? else cost += 140; // ?¬¬????????? } return cost; } public static void main(String[] args){ P01 p01 = new P01(); } }
Main.java:5: error: ';' expected Scanner scan = new Scanner(System.in) ^ 1 error
s544411742
p00216
Java
import java.util.Scanner; public class P01{ public P01(){ Scanner scan = new Scanner(System.in) for(int w; scan.hasNextInt() && w >= 0;){ System.out.println( 4280-getCost(w)); } } public int getCost(int w){ int cost = 1150; for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; else if ( 30 < i ) cost += 160; else cost += 140; } return cost; } public static void main(String[] args){ P01 p01 = new P01(); } }
Main.java:5: error: ';' expected Scanner scan = new Scanner(System.in) ^ 1 error
s263924732
p00216
Java
import java.util.Scanner; public class P01{ public P01(){ Scanner scan = new Scanner(System.in) for(int w; scan.hasNextInt() && w >= 0;){ System.out.println( 4280-getCost(w)); } } public int getCost(int w){ int cost = 1150; // ?¬¬????????? for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; // ?¬¬????????? else if ( 30 < i ) cost += 160; // ?¬¬????????? else cost += 140; // ?¬¬????????? } return cost; } public static void main(String[] args){ P01 p01 = new P01(); } }
Main.java:5: error: ';' expected Scanner scan = new Scanner(System.in) ^ 1 error
s641472447
p00216
Java
import java.util.Scanner; public class P01{ public P01(){ Scanner scan = new Scanner(System.in) for(int w; scan.hasNextInt() && w >= 0;){ System.out.println( 4280-getCost(w)); } } public int getCost(int w){ int cost = 1150; // ?¬¬????????? for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; // ?¬¬????????? else if ( 30 < i ) cost += 160; // ?¬¬????????? else cost += 140; // ?¬¬????????? } return cost; } public static void main(String[] args){ P01 p01 = new P01(); } }
Main.java:5: error: ';' expected Scanner scan = new Scanner(System.in) ^ 1 error
s394147235
p00216
Java
import java.util.Scanner; public class P01{ public P01(){ Scanner scan = new Scanner(System.in) for(int w; scan.hasNextInt() && w >= 0;){ System.out.println( 4280-getCost(w)); } } public int getCost(int w){ int cost = 1150; // ?¬¬????????? for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; // ?¬¬????????? else if ( 30 < i ) cost += 160; // ?¬¬????????? else cost += 140; // ?¬¬????????? } return cost; } public static void main(String[] args){ P01 p01 = new P01(); } }
Main.java:5: error: ';' expected Scanner scan = new Scanner(System.in) ^ 1 error
s407955935
p00216
Java
import java.util.Scanner; public class P01{ public P01(){ Scanner scan = new Scanner(System.in) for(int w; scan.hasNextInt() && w >= 0;){ System.out.println( 4280-getCost(w)); } } public int getCost(int w){ int cost = 1150; // ?¬¬????????? for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; // ?¬¬????????? else if ( 30 < i ) cost += 160; // ?¬¬????????? else cost += 140; // ?¬¬????????? } return cost; } public static void main(String[] args){ P01 p01 = new P01(); } }
Main.java:5: error: ';' expected Scanner scan = new Scanner(System.in) ^ 1 error
s682152984
p00216
C
#include<iostream> using namespace std; int getCost(int w){ int cost = 1150; // ?¬¬????????? for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; // ?¬¬????????? else if ( 30 < i ) cost += 160; // ?¬¬????????? else cost += 140; // ?¬¬????????? } return cost;} int main(){ for( int w; cin >> w && w >= 0; ) { cout << 4280 - getCost(w) << endl; } return 0; }
main.c:1:9: fatal error: iostream: No such file or directory 1 | #include<iostream> | ^~~~~~~~~~ compilation terminated.
s957050628
p00216
C
#include<iostream> using namespace std; int getCost(int w){ int cost = 1150; // ?¬¬????????? for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; // ?¬¬????????? else if ( 30 < i ) cost += 160; // ?¬¬????????? else cost += 140; // ?¬¬????????? } return cost; } int main(){ for( int w; cin >> w && w >= 0; ) { cout << 4280 - getCost(w) << endl; } return 0; }
main.c:1:9: fatal error: iostream: No such file or directory 1 | #include<iostream> | ^~~~~~~~~~ compilation terminated.
s784743471
p00216
C
#include<iostream> using namespace std; int getCost(int w){ int cost = 1150; // ?¬¬????????? for (int i = 11; i <= w; i++ ){ if ( i <= 20 ) cost += 125; // ?¬¬????????? else if ( 30 < i ) cost += 160; // ?¬¬????????? else cost += 140; // ?¬¬????????? } return cost; } int main(){ for( int w; cin >> w && w >= 0; ) { cout << 4280 - getCost(w) << endl; } return 0; } ?§£??????(
main.c:1:9: fatal error: iostream: No such file or directory 1 | #include<iostream> | ^~~~~~~~~~ compilation terminated.
s117384054
p00216
C
#include<stdio.h> int main(void) { int a,d=1150; while(scanf("%d",&a),a!=-1){ if(a>30){ d=d+160*(a-30); a=30; } if(a>20){ d=d+140*(a-20); a=20; } if(a>10) d=d+140*(a-10); d=10; } if(a<=10){ printf("%d?\n",d-4280); } } return 0; }
main.c:22:1: error: expected identifier or '(' before 'return' 22 | return 0; | ^~~~~~ main.c:23:1: error: expected identifier or '(' before '}' token 23 | } | ^
s528268551
p00216
C
#include <stdio.h> int main() { int b,c,d,e,w,e,f; int x; for(;;){ scanf("%d",&w); if(w==-1){ break; } if(w<=10){ b=1150; } else if(w>10&&w<=20){ d=w-10; b=1150+d*125; } else if(w>20&&w<=30){ e=w-20; b=1150+1250+e*140; } else if(w>30){ f=w-30; b=1150+1250+1400+f*160; } c=4280-b; printf("%d\n",c); } return 0; }
main.c: In function 'main': main.c:4:23: error: redeclaration of 'e' with no linkage 4 | int b,c,d,e,w,e,f; | ^ main.c:4:19: note: previous declaration of 'e' with type 'int' 4 | int b,c,d,e,w,e,f; | ^
s926405866
p00216
C
main(w,s){for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;}
main.c:1:1: error: return type defaults to 'int' [-Wimplicit-int] 1 | main(w,s){for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~ main.c: In function 'main': main.c:1:1: error: type of 'w' defaults to 'int' [-Wimplicit-int] main.c:1:1: error: type of 's' defaults to 'int' [-Wimplicit-int] main.c:1:23: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration] 1 | main(w,s){for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~ main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf' +++ |+#include <stdio.h> 1 | main(w,s){for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} main.c:1:23: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch] 1 | main(w,s){for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~ main.c:1:23: note: include '<stdio.h>' or provide a declaration of 'scanf' main.c:1:41: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 1 | main(w,s){for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~~ main.c:1:41: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:1:41: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch] main.c:1:41: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:1:109: error: lvalue required as left operand of assignment 1 | main(w,s){for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~
s892261929
p00216
C
main(){for(int w,s;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;}
main.c:1:1: error: return type defaults to 'int' [-Wimplicit-int] 1 | main(){for(int w,s;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~ main.c: In function 'main': main.c:1:27: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration] 1 | main(){for(int w,s;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~ main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf' +++ |+#include <stdio.h> 1 | main(){for(int w,s;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} main.c:1:27: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch] 1 | main(){for(int w,s;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~ main.c:1:27: note: include '<stdio.h>' or provide a declaration of 'scanf' main.c:1:45: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 1 | main(){for(int w,s;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~~ main.c:1:45: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:1:45: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch] main.c:1:45: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:1:113: error: lvalue required as left operand of assignment 1 | main(){for(int w,s;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~
s570295091
p00216
C
main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;}
main.c:1:1: error: return type defaults to 'int' [-Wimplicit-int] 1 | main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~ main.c: In function 'main': main.c:1:28: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration] 1 | main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~ main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf' +++ |+#include <stdio.h> 1 | main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} main.c:1:28: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch] 1 | main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~ main.c:1:28: note: include '<stdio.h>' or provide a declaration of 'scanf' main.c:1:46: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 1 | main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~~ main.c:1:46: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:1:46: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch] main.c:1:46: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:1:114: error: lvalue required as left operand of assignment 1 | main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~
s156308178
p00216
C
int main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;}
main.c: In function 'main': main.c:1:32: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration] 1 | int main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~ main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf' +++ |+#include <stdio.h> 1 | int main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} main.c:1:32: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch] 1 | int main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~ main.c:1:32: note: include '<stdio.h>' or provide a declaration of 'scanf' main.c:1:50: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration] 1 | int main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~~~~~ main.c:1:50: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:1:50: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch] main.c:1:50: note: include '<stdio.h>' or provide a declaration of 'printf' main.c:1:118: error: lvalue required as left operand of assignment 1 | int main(){int w,s;for(;s=1150,scanf("%d",&w),~w;printf("%d\n",4280-s))w<11?0:w<21?s+=w*125-1250:w<31?s+=140*w-1550:s+=w*160-2150;} | ^~
s670982860
p00216
C
#include <iostream> int main(){ int w; while(std::cin >> w, w+1){ int p = 1150; if(w > 30)p += 2650 + (w-30) * 160; else if(w > 20)p += 1250 + (w-20) * 140; else if(w > 10)p += (w-10) * 125; std::cout << 4280 - p << std::endl; } }
main.c:1:10: fatal error: iostream: No such file or directory 1 | #include <iostream> | ^~~~~~~~~~ compilation terminated.
s795960780
p00216
C
#include<stdio.h> int main(){ int w; int m = 1150; int t; do{ scanf("%d", &w); t = w; t -= 30; } if(w > 30){ m += 10 * 125 + 10 * 140 + t * 160; }else if(w > 20){ t = w - 20; m += 10 * 125 + t *140; }else if(w > 10){ t = w - 10; m += r * 125; }else{ m = m; } printf("%d\n", 4280 - m); }while(scanf("%d", w) != -1); return 0; }
main.c: In function 'main': main.c:13:17: error: expected 'while' before 'if' 13 | if(w > 30){ | ^~ main.c:15:18: error: 'else' without a previous 'if' 15 | }else if(w > 20){ | ^~~~ main.c:20:30: error: 'r' undeclared (first use in this function) 20 | m += r * 125; | ^ main.c:20:30: note: each undeclared identifier is reported only once for each function it appears in main.c: At top level: main.c:25:10: error: expected identifier or '(' before 'while' 25 | }while(scanf("%d", w) != -1); | ^~~~~ main.c:26:9: error: expected identifier or '(' before 'return' 26 | return 0; | ^~~~~~ main.c:27:1: error: expected identifier or '(' before '}' token 27 | } | ^
s934497347
p00216
C
#include <iostream> using namespace std; int main(){ int w,money,flag,i; while(1){ money = 1150; cin >> w; if(w == -1){ break; } if(w <= 10){ cout << 4280 - money << endl; } else { w -= 10; flag = 9; for(i=w;i>=1;i--){ flag++; if(flag < 20){ money += 125; } else if(flag < 30){ money += 140; } else if(flag < 40){ money += 160; } } cout << 4280 - money << endl; } } }
main.c:1:10: fatal error: iostream: No such file or directory 1 | #include <iostream> | ^~~~~~~~~~ compilation terminated.
s784647450
p00216
C
include<stdio.h> main(){ int i,w,en=0,flg; while(1){ scanf("%d",&w); if(w==-1)break; for(i=11,en=1150;i<=w;i++){ if(i<=20)en+=125; else if(i<=30)en+=140; else en+=160; } printf("%d\n",4280-en); } return 0; }
main.c:1:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token 1 | include<stdio.h> | ^
s084396527
p00216
C
#include <stdio.h> int main(void) { int w, a; while(scanf("%d", &w) != EOF && w != -1){ int rates = 1150; if(w > 30){ rates += (1250 + 1400); if() rates += (w - 30) * 160; } else{ if(w > 20){ rates += 1250; rates += (w % 20) * 140; } if(10 < w && w < 20){ rates += (w % 10) * 125; } } printf("%d\n", 4280 - rates); } return 0; }
main.c: In function 'main': main.c:14:28: error: expected expression before ')' token 14 | if() | ^
s390769742
p00216
C++
/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
s556073513
p00216
C++
#include<iostream> using namespace srd; int main(){ int w,r; while(1){ cin >> w; if(w<=10)r = 4280-1150; else if(10<w<=20)r = 4280 - (1150 + (w-10) * 125); else if(20<w<=30)r = 4280 - (1150 + 1250 + (w-20) * 140); else if(30<w)r = 4280 - (1150 + 1250 + 1400 + (w-20) * 160); else if(w==-1)break; cout << r << "\n"; } return 0; }
a.cc:2:17: error: 'srd' is not a namespace-name 2 | using namespace srd; | ^~~ a.cc: In function 'int main()': a.cc:7:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'? 7 | cin >> w; | ^~~ | std::cin In file included from a.cc:1: /usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here 62 | extern istream cin; ///< Linked to standard input | ^~~ a.cc:15:9: error: 'cout' was not declared in this scope; did you mean 'std::cout'? 15 | cout << r << "\n"; | ^~~~ | std::cout /usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here 63 | extern ostream cout; ///< Linked to standard output | ^~~~