submission_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 3 values | code stringlengths 1 522k | compiler_output stringlengths 43 10.2k |
|---|---|---|---|---|
s707086662 | p00242 | C++ | #include<string>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
for(;;){
int n;
vector<string> str;
char c_string[1000];
vector<string> find_moji;
string temp;
int sub_begin;
int cont;
char moji;
bool cont_flg = false;
int map_cont = 0;
cin >> n;
if(n == 0){
break;
}
set<string> find_moji2;
for(int i = 0; i < n; i++){
gets(c_string);
str.push_back(c_string);
}
cin >> moji;
//先頭で始まる文字まで飛ばして、find_mojiに突っ込む
for(int i = 0; i < n; i++){
temp = str[i];
for(int j = 0; j < temp.size(); j++){
if(temp[j] == moji && (j == 0 || temp[j-1] == ' ')){
sub_begin = j;
cont_flg = true;
cont = 0;
//スペースまでカウント開始
}
if((temp[j] == ' '|| j == temp.size()-1) && cont_flg == true){
cont_flg = false;
string ss = temp.substr(sub_begin, cont+1);
if(ss[ss.size()-1] == ' '){
ss = temp.substr(sub_begin, cont);
}
find_moji.push_back(ss);
find_moji2.insert(ss);
map_cont++;
}
if(cont_flg == true){
cont++;
}
}
}
/*
sort(find_moji.begin(), find_moji.end());
for(int i = 0; i < find_moji.size(); i++){
cout << find_moji2[i] << endl;
if(i > 3){
break;
}
}
*/
bool come = false;
int cont2 = 0;
set<string>::iterator _ite = find_moji2.begin();
while(_ite != find_moji2.end()){
cout << *_ite << endl;
_ite++;
come = true;
cont2++;
if(cont2 == 5){
break;
}
}
if(come == false){
cout << "NA" << endl;
}
}
}
| a.cc: In function 'int main()':
a.cc:37:25: error: 'gets' was not declared in this scope; did you mean 'getw'?
37 | gets(c_string);
| ^~~~
| getw
|
s545705766 | p00242 | C++ | #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>
using namespace std;
bool cmp(pair<string, int> a, pair<string, int> b) {
return a.second > b.second || (a.second == b.second && a.first < b.first);
}
int main() {
for (;;) {
int n;
cin >> n;
if (!n) return 0;
string s, l;
getline(cin, l);
for (int i = 0; i < n; i++) {
getline(cin, l);
s += l;
s += ' ';
}
char k;
cin >> k;
int c = 0;
char w[21];
map<string, int> freq;
for (int i = 0; i < s.length(); i++)
if (s[i] == ' ' && c) {
w[c] = '\0';
if (w[0] == k) freq[w]++;
c = 0;
} else
w[c++] = s[i];
vector<pair<string, int> > v;
for (map<string, int>::iterator p = freq.begin(); p != freq.end(); ++p)
v.push_back(*p);
if (v.empty())
cout << "NA" << endl;
else {
sort(v.begin(), v.end(), cmp);
for (int i = 0; i < min(v.size(), 5u); i++)
cout << v[i].first << ' ';
cout << endl;
}
}
} | a.cc: In function 'int main()':
a.cc:49:30: error: no matching function for call to 'min(std::vector<std::pair<std::__cxx11::basic_string<char>, int> >::size_type, unsigned int)'
49 | for (int i = 0; i < min(v.size(), 5u); i++)
| ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
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:49:30: note: deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'unsigned int')
49 | for (int i = 0; i < min(v.size(), 5u); 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:
/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:49:30: note: mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
49 | for (int i = 0; i < min(v.size(), 5u); i++)
| ~~~^~~~~~~~~~~~~~
|
s231633416 | p00242 | C++ | #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <queue>
#include <string>
#include <map>
#include <vector>
using namespace std;
bool cmp(pair<string, int> a, pair<string, int> b) {
return a.second > b.second || (a.second == b.second && a.first < b.first);
}
int main() {
for (;;) {
int n;
cin >> n;
if (!n) return 0;
string s, l;
getline(cin, l);
for (int i = 0; i < n; i++) {
getline(cin, l);
s += l;
s += ' ';
}
char k;
cin >> k;
int c = 0;
char w[21];
map<string, int> freq;
for (int i = 0; i < s.length(); i++)
if (s[i] == ' ' && c) {
w[c] = '\0';
if (w[0] == k) freq[w]++;
c = 0;
} else
w[c++] = s[i];
vector<pair<string, int> > v;
for (map<string, int>::iterator p = freq.begin(); p != freq.end(); ++p)
v.push_back(*p);
if (v.empty())
cout << "NA" << endl;
else {
sort(v.begin(), v.end(), cmp);
for (int i = 0; i < min(v.size(), 5); i++)
cout << v[i].first << ' ';
cout << endl;
}
}
} | a.cc: In function 'int main()':
a.cc:49:30: error: no matching function for call to 'min(std::vector<std::pair<std::__cxx11::basic_string<char>, int> >::size_type, int)'
49 | for (int i = 0; i < min(v.size(), 5); i++)
| ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
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:49:30: note: deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
49 | for (int i = 0; i < min(v.size(), 5); 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:
/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:49:30: note: mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
49 | for (int i = 0; i < min(v.size(), 5); i++)
| ~~~^~~~~~~~~~~~~
|
s566256396 | p00242 | C++ | #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int INF = 1001001001;
const double EPS = 1e-10;
int main()
{
int n;
while(scanf("%d%*c", &n), n){
char line[2048];
map<string, int> dict;
rep(i, n){
fgets(line, sizeof(line), stdin);
stringstream sstr(line);
for(string word; sstr >> word;)
dict[word]--;
}
vector<pair<int, string> > a;
scanf("%s", line);
for(map<string, int>::iterator itr=dict.begin(); itr!=dict.end(); ++itr){
if(itr->first[0] == line[0])
a.push_back(make_pair(itr->second, itr->first));
}
if(a.empty())
puts("NA");
else{
sort(a.begin(), a.end());
rep(i, min(5u, a.size()))
printf("%s%s", i ? " " : "", a[i].second.c_str());
puts("");
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:55:35: error: no matching function for call to 'min(unsigned int, std::vector<std::pair<int, std::__cxx11::basic_string<char> > >::size_type)'
55 | rep(i, min(5u, a.size()))
| ~~~^~~~~~~~~~~~~~
a.cc:21:40: note: in definition of macro 'reps'
21 | #define reps(i,f,n) for(int i=f; i<int(n); ++i)
| ^
a.cc:55:25: note: in expansion of macro 'rep'
55 | rep(i, min(5u, a.size()))
| ^~~
In file included from /usr/include/c++/14/algorithm:60,
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:55:35: note: deduced conflicting types for parameter 'const _Tp' ('unsigned int' and 'std::vector<std::pair<int, std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'})
55 | rep(i, min(5u, a.size()))
| ~~~^~~~~~~~~~~~~~
a.cc:21:40: note: in definition of macro 'reps'
21 | #define reps(i,f,n) for(int i=f; i<int(n); ++i)
| ^
a.cc:55:25: note: in expansion of macro 'rep'
55 | rep(i, min(5u, a.size()))
| ^~~
/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:55:35: note: mismatched types 'std::initializer_list<_Tp>' and 'unsigned int'
55 | rep(i, min(5u, a.size()))
| ~~~^~~~~~~~~~~~~~
a.cc:21:40: note: in definition of macro 'reps'
21 | #define reps(i,f,n) for(int i=f; i<int(n); ++i)
| ^
a.cc:55:25: note: in expansion of macro 'rep'
55 | rep(i, min(5u, a.size()))
| ^~~
|
s519178422 | p00242 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <deque>
using namespace std;
int main(void)
{
int n,k;
char c;
string str,s;
map<string,int> words;
map<string,int>::iterator it;
deque< pair<string,int> > choice;
while(1){
cin >> n;
cin.ignore();
if(n==0) break;
for(int i=0;i<n;i++){
getline(cin,str);
str+=' ';
while(!str.empty()){
for(k=0;str[k]!=' '&&str[k]!='\0';k++);
s=str.substr(0,k);
str=str.substr(k+1);
words[s]++;
}
}
cin >> c;
for(it=words.begin();it!=words.end();++it){
if((*it).first[0]==c) choice.push_back(pair<string,int>((*it).first,(*it).second));
}
if(choice.empty()) cout << "NA";
else{
sort(choice.begin(),choice.end());
for(int i=0;i<5&&i<choice.size();i++) cout << choice[i].first << " ";
}
cout << endl;
words.clear();
choice.clear();
}
return 0;
} | a.cc: In function 'int main()':
a.cc:35:25: error: 'sort' was not declared in this scope; did you mean 'short'?
35 | sort(choice.begin(),choice.end());
| ^~~~
| short
|
s335592759 | p00242 | C++ | #include<iostream>
#include<algorithm>
#include<iterator>
#include<string>
#include<sstream>
#include<vector>
#include<map>
using namespace std;
struct pard {
bool operator()(const pair<string, int>& _Left, const pair<string, int>& _Right) {
return _Left.second != _Right.second ? _Left.second > _Right.second : _Left.first < _Right.first;
}
};
int main() {
int n;
string line;
char initial;
while(cin >> n && n) {
cin.ignore(numeric_limits<streamsize>::max(), '\n');
map<string, int> date_m;
while(n--) {
getline(cin, line);
istringstream iss(line);
for(istream_iterator<string> ite = istream_iterator<string>(iss); ite != istream_iterator<string>(); ++ite) {
++date_m.insert(make_pair(*ite, 0)).first->second;
}
}
cin >> initial;
vector< pair<string, int> > date_v(5);
vector< pair<string, int> >::iterator first = date_v.begin(), last = partial_sort_copy(
date_m.lower_bound(string(1, initial)), date_m.lower_bound(string(1, initial + 1)),
date_v.begin(), date_v.end(), pard()
);
cout << (first != last ? first++->first : "NA");
while(first != last) cout << ' ' << first++->first;
cout << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:23:28: error: 'numeric_limits' was not declared in this scope
23 | cin.ignore(numeric_limits<streamsize>::max(), '\n');
| ^~~~~~~~~~~~~~
a.cc:23:53: error: expected primary-expression before '>' token
23 | cin.ignore(numeric_limits<streamsize>::max(), '\n');
| ^
a.cc:23:59: error: no matching function for call to 'max()'
23 | cin.ignore(numeric_limits<streamsize>::max(), '\n');
| ~~~~~^~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 0 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate expects 2 arguments, 0 provided
|
s984861120 | p00242 | C++ | #include <bits/stdc++.h>
#include <map>
using namespace std;
int main(){
int n;
while(cin >> n, n){
cin.ignore();
map<string, int> dic;
for(int i=0; i < n; i++){
string s;
getline(cin, s);
s += " ";
while(s.size() != 0){
string word = s.substr(0, s.find_first_of(" "));
s = s.substr(s.find_first_of(" ")+1);
dic[word]++;
}
}
string initial;
cin >> initial;
bool isFirst = true;
map<string, int>::iterator it = dic.begin();
int count = 0;
while(it != dic.end() && count < 5){
if((*it).first.substr(0 ,1) == initial){
if(isFirst){cout << (*it).first; isFirst = false;}
else cout << " " << (*it).first;
count++;
}
it++;
}
if(count == 0) cout << "NA" << endl;
else cout << endl;
dic.clear();
| a.cc: In function 'int main()':
a.cc:37:21: error: expected '}' at end of input
37 | dic.clear();
| ^
a.cc:7:23: note: to match this '{'
7 | while(cin >> n, n){
| ^
a.cc:37:21: error: expected '}' at end of input
37 | dic.clear();
| ^
a.cc:5:11: note: to match this '{'
5 | int main(){
| ^
|
s553726799 | p00243 | Java |
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main {
int INF = 1 << 28;
int w, h;
int min;
// char[][] p;
void run() {
Scanner sc = new Scanner(System.in);
for(;;) {
w = sc.nextInt();
h = sc.nextInt();
if( (w|h) == 0 ) break;
p = new char[h+2][w+2];
for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) {
String str = sc.next();
// p[i][j] = str.charAt(0);
}
min = 10 * 10;
// dfs(p, 0, p[1][1]);
System.out.println(min);
}
}
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};
char clrs[] = {'R', 'G', 'B'};
boolean[][] used;
LinkedList<Character> list;
void dfs(char[][] p, int d, char c) {
used = new boolean[h+2][w+2];
list = new LinkedList<Character>();
dfs(p, 1, 1, p[1][1], c);
list.clear();
used = new boolean[h+2][w+2];
int cnt = dfs(p, 1, 1, p[1][1], p[1][1]);
debug(c, cnt);
if( cnt == w*h ) {
min = min(min, d);
return;
}
HashSet<Character> clrs = new HashSet<Character>(list);
debug(clrs);
for(char clr: clrs) {
char[][] tmp = new char[h+2][w+2];
for(int k=0;k<h+2;k++) for(int j=0;j<w+2;j++) tmp[k][j] = p[k][j];
dfs(tmp, d+1, clr);
}
}
int dfs(char[][] p, int x, int y, char c, char to) {
if(p[y][x] != c) {
if(p[y][x] != 0) list.add(p[y][x]);
return 0;
}
used[y][x] = true;
p[y][x] = to;
int cnt = 1;
for(int i=0;i<4;i++) if(!used[y+dy[i]][x+dx[i]]) cnt += dfs(p, x+dx[i], y+dy[i], c, to);
return cnt;
}
public static void main(String[] args) {
new Main().run();
}
void debug(Object... os) {
// System.err.println(Arrays.deepToString(os));
}
} | Main.java:20: error: cannot find symbol
p = new char[h+2][w+2];
^
symbol: variable p
location: class Main
1 error
|
s202037485 | p00243 | C | #include <stdio.h>
#include <time.h>
char s[100];
int main(void){
int x, y;
char c;
for(; scanf("%d%d%c", &x, &y, &c);,y){
if( c != '\n' ){
clock_t c1 = clock() + CLOCKS_PER_SEC * 0.02 * c;
while( clock() < c1 );
return 0;
}
for( int i = 0; i < y; ++i ){
fgets( s, 50, stdin);
}
}
return 0;
} | main.c: In function 'main':
main.c:9:43: error: expected expression before ',' token
9 | for(; scanf("%d%d%c", &x, &y, &c);,y){
| ^
|
s118155191 | p00243 | C++ | #include<iostream>
#include<queue>
using namespace std;
struct Grid{
char g[11][11];
int cnt;
};
void draw(Grid& grid,char f,char c,int x,int y){
if(grid.g[x][y] != f){
return;
}
grid.g[x][y] = c;
draw(grid,f,c,x-1,y);
draw(grid,f,c,x+1,y);
draw(grid,f,c,x,y-1);
draw(grid,f,c,x,y+1);
}
int main(){
int x,y;
while(1){
cin >> x >> y;
if(x==0 && y==0){
break;
}
Grid st;
for(int i=0; i<y; i++){
for(int j=0; j<x; j++){
cin >> start.g[j][i];
}
}
char fc = start.g[0][0];
bool flag = true;
for(int i=0; i<y; i++){
for(int j=0; j<x; j++){
if(start.g[j][i]!=fc){
flag = false;
break;
}
}
if(!flag){
break;
}
}
if(flag){
cout << 0 << endl;
continue;
}
start.cnt = 0;
queue<Grid> q;
q.push(start);
while(1){
Grid bg = q.front();
q.pop();
bg.cnt++;
Grid tmp = bg;
fc = tmp.g[0][0];
if(fc != 'R'){
draw(tmp,fc,'R',0,0);
flag = true;
for(int i=0; i<y; i++){
for(int j=0; j<x; j++){
if(tmp.g[j][i]!='R'){
flag = false;
break;
}
}
if(!flag){
break;
}
}
if(flag){
cout << tmp.cnt << endl;
break;
}
q.push(tmp);
tmp = bg;
}
if(fc != 'G'){
draw(tmp,fc,'G',0,0);
flag = true;
for(int i=0; i<y; i++){
for(int j=0; j<x; j++){
if(tmp.g[j][i]!='G'){
flag = false;
break;
}
}
if(!flag){
break;
}
}
if(flag){
cout << tmp.cnt << endl;
break;
}
q.push(tmp);
tmp = bg;
}
if(fc != 'B'){
draw(tmp,fc,'B',0,0);
flag = true;
for(int i=0; i<y; i++){
for(int j=0; j<x; j++){
if(tmp.g[j][i]!='B'){
flag = false;
break;
}
}
if(!flag){
break;
}
}
if(flag){
cout << tmp.cnt << endl;
break;
}
q.push(tmp);
tmp = bg;
}
}
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:38:22: error: 'start' was not declared in this scope
38 | cin >> start.g[j][i];
| ^~~~~
a.cc:42:17: error: 'start' was not declared in this scope
42 | char fc = start.g[0][0];
| ^~~~~
|
s814419627 | p00243 | C++ | #include<cstdio>
#include<algorithm>
#include<string>
#include<queue>
#define rep(i,a) for( int i = 0; i != (a); ++i )
const std::string RGB = "RGB";
int x, y;
short fld[10][10];
struct State
{
short st[10][10];
int cnt;
State( short fld[10][10], int cnt )
: cnt( cnt )
{
rep( i, y )
rep( j, x )
st[i][j] = fld[i][j];
}
};
void paint( int px, int py, int prvc, int c )
{
static const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
if( fld[py][px] != prvc )
return;
fld[py][px] = c;
rep( i, 4 )
{
int nx = px+dx[i], ny = py+dy[i];
if( nx >= 0 && nx < x && ny >= 0 && ny < y && fld[ny][nx] == prvc )
paint( nx, ny, prvc, c );
}
return;
}
int main()
{
while( scanf( "%d%d", &x, &y ), x|y )
{
rep( i, y )
{
rep( j, x )
{
char ch[2];
scanf( "%s", ch );
fld[i][j] = RGB.find( ch );
}
}
std::queue<State> que;
for( que.push( State( fld, 0 ) ); !que.empty(); que.pop() )
{
State s = que.front();
bool fl = true;
rep( i, y )
{
rep( j, x )
{
fl &= s.st[i][j] == s.st[0][0];
fld[i][j] = s.st[i][j];
}
}
if( fl )
{
printf( "%d\n", s.cnt );
break;
}
rep( c, 3 )
{
if( c == **s.st )
continue;
if( c )
memcpy( fld, s.st, sizeof( fld ) );
paint( 0, 0, **fld, c );
que.push( State( fld, s.cnt+1 ) );
}
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:88:41: error: 'memcpy' was not declared in this scope
88 | memcpy( fld, s.st, sizeof( fld ) );
| ^~~~~~
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 | #define rep(i,a) for( int i = 0; i != (a); ++i )
|
s066350267 | p00243 | C++ | #include<bits/stdc++.h>
using namespace std;
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
int H,W;
int fld[10][10];
int lim;
bool change(int y,int x,int c,int f){
fld[y][x]=c;
for(int d=0;d<4;d++){
int ny=y+dy[d],nx=x+dx[d];
if(ny<0||ny>=H||nx<0||nx>=W||fld[ny][nx]!=f)continue;
change(ny,nx,c,f);
}
}
bool dfs(int t=0){
bool ok=true;
for(int i=0;i<H;i++)for(int j=0;j<W;j++){
if(fld[0][0]!=fld[i][j])ok=false;
}
if(ok)return true;
if(t==lim)return false;
int _fld[10][10];
for(int i=0;i<H;i++)for(int j=0;j<W;j++){
_fld[i][j]=fld[i][j];
}
bool ret=false;
for(int k=0;k<3;k++)if(k!=fld[0][0]){
change(0,0,k,fld[0][0])
ret|=dfs(t+1);
for(int i=0;i<H;i++)for(int j=0;j<W;j++){
fld[i][j]=_fld[i][j];
}
}
return ret;
}
int main(){
while(cin>>W>>H,W||H){
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
char c;
cin>>c;
switch(c){
case 'R':fld[i][j]=0;break;
case 'G':fld[i][j]=1;break;
case 'B':fld[i][j]=2;break;
}
}
}
for(lim=0;;lim++)if(dfs())break;
cout<<lim<<endl;
}
return 0;
} | a.cc: In function 'bool change(int, int, int, int)':
a.cc:18:1: warning: no return statement in function returning non-void [-Wreturn-type]
18 | }
| ^
a.cc: In function 'bool dfs(int)':
a.cc:35:32: error: expected ';' before 'ret'
35 | change(0,0,k,fld[0][0])
| ^
| ;
36 | ret|=dfs(t+1);
| ~~~
|
s363584774 | p00243 | C++ | # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <set>
# include <map>
# include <stack>
using namespace std;
# define M_PI 3.141592
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define pri_max 60000
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl;
typedef pair<int, int> pii;
int x, y;
char a[20][20];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,-1,0,1 };
map<string, int> m;
int dfs(int z)
{
bool ok = true;
string tmp;
char b[20][20];
for (int i = 1; i <= y; i++)
{
for (int j = 1; j <= x; j++)
{
if (a[1][1] != a[i][j])ok = false;
tmp += a[i][j];
b[i][j] = a[i][j];
}
}
if (ok)return z;
if (!m.count(tmp))m[tmp] = z;
else if (m[tmp] <= z)return INT_MAX;
char ord[4] = "RGB";
int ans = INT_MAX;
for (int i = 0; i < 3; i++)
{
char o, t;
o = a[1][1]; t = ord[i];
if (o == t)continue;
a[1][1] = t;
queue<pii> que;
que.push(pii(1, 1));
while (!que.empty())
{
pii now = que.front(); que.pop();
for (int l = 0; l < 4; l++)
{
pii next;
next.first = now.first + dx[l];
next.second = now.second + dy[l];
if (a[next.first][next.second] == o)
{
a[next.first][next.second] = t;
que.push(next);
}
}
}
ans = min(ans, dfs(z + 1));
for (int l = 1; l <= y; l++)
{
for (int k = 1; k <= x; k++)
{
a[l][k] = b[l][k];
}
}
}
return ans;
}
int main()
{
while (cin >> x >> y&&x&&y)
{
memset(a, 0, sizeof a);
m.clear(); M.clear();
for (int i = 1; i <= y; i++)
{
for (int j = 1; j <= x; j++)
{
cin >> a[i][j];
}
}
cout << dfs(0) << endl;
}
} | a.cc:23:10: warning: "M_PI" redefined
23 | # define M_PI 3.141592
| ^~~~
In file included from /usr/include/c++/14/cmath:47,
from a.cc:15:
/usr/include/math.h:1121:10: note: this is the location of the previous definition
1121 | # define M_PI 3.14159265358979323846 /* pi */
| ^~~~
a.cc: In function 'int main()':
a.cc:112:28: error: 'M' was not declared in this scope
112 | m.clear(); M.clear();
| ^
|
s599239211 | p00243 | C++ | #include <queue>
#include <vector>
#include <iostream>
using namespace std;
int H, W; char c;
int main() {
ios::sync_with_stdio(false);
while (cin >> W >> H, H | W) {
vector<vector<int> > a(H, vector<int>(W));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> c;
if (c == 'R') a[i][j] = 0;
if (c == 'G') a[i][j] = 1;
if (c == 'B') a[i][j] = 2;
}
}
vector<vector<pair<int, int> > > comp;
vector<vector<bool> > vis(H, vector<bool>(W, false));
vector<int> dir({ 0, 1, 0, -1 });
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (vis[i][j]) continue;
comp.push_back(vector<pair<int, int> >({ make_pair(j, i) }));
vis[i][j] = true;
queue<pair<int, int> > que;
que.push(make_pair(j, i));
while (!que.empty()) {
pair<int, int> u = que.front(); que.pop();
for (int k = 0; k < 4; k++) {
int tx = u.first + dir[k], ty = u.second + dir[k ^ 1];
if (0 <= tx && tx < W && 0 <= ty && ty < H && !vis[ty][tx] && a[u.second][u.first] == a[ty][tx]) {
vis[ty][tx] = true;
comp.back().push_back(make_pair(tx, ty));
que.push(make_pair(tx, ty));
}
}
}
}
}
vector<int> col(comp.size());
for (int i = 0; i < comp.size(); i++) {
for (pair<int, int> j : comp[i]) {
col[i] = a[j.second][j.first];
a[j.second][j.first] = i;
}
}
vector<vector<int> > G(comp.size());
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (j + 1 != W && a[i][j] != a[i][j + 1]) {
G[a[i][j]].push_back(a[i][j + 1]);
G[a[i][j + 1]].push_back(a[i][j]);
}
if (i + 1 != H && a[i][j] != a[i + 1][j]) {
G[a[i][j]].push_back(a[i + 1][j]);
G[a[i + 1][j]].push_back(a[i][j]);
}
}
}
for (int i = 0; i < G.size(); i++) {
sort(G[i].begin(), G[i].end());
int ptr = unique(G[i].begin(), G[i].end()) - G[i].begin();
G[i].erase(G[i].begin() + ptr, G[i].end());
}
for (int i = 0; ; i++) {
bool ok = false;
for (int j = 0; j < 1 << i; j++) {
vector<int> w1(col);
for (int k = 0; k < i; k++) {
int r = (w1[a[0][0]] + ((j & (1 << k)) ? 2 : 1)) % 3;
queue<int> que2; que2.push(a[0][0]);
vector<bool> vis2(G.size()); vis2[a[0][0]] = true;
while (!que2.empty()) {
int u = que2.front(); que2.pop();
for (int l : G[u]) {
if (!vis2[l] && w1[u] == w1[l]) {
vis2[l] = true;
que2.push(l);
}
}
}
for (int l = 0; l < G.size(); l++) {
if (vis2[l]) w1[l] = r;
}
}
bool flag = true;
for (int k = 1; k < G.size(); k++) {
if (w1[0] != w1[k]) {
flag = false;
break;
}
}
if (flag) {
ok = true;
break;
}
}
if (ok) {
cout << i << endl;
break;
}
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:62:25: error: 'sort' was not declared in this scope; did you mean 'short'?
62 | sort(G[i].begin(), G[i].end());
| ^~~~
| short
a.cc:63:35: error: 'unique' was not declared in this scope
63 | int ptr = unique(G[i].begin(), G[i].end()) - G[i].begin();
| ^~~~~~
|
s724568228 | p00243 | C++ | #include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
using Mat = vector<vector<char>>;
constexpr char col[] = {'R', 'G', 'B'};
constexpr int MAX = 10;
constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};
int W, H;
Mat M;
bool visited[MAX][MAX];
bool in_field(int x, int y)
{
return (0 <= x && x < W && 0 <= y && y < H);
}
void paint(Mat& m, int x, int y, char nc, char c)
{
if (visited[y][x]) return;
visited[y][x] = 1;
m[y][x] = nc;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (in_field(nx, ny) && m[ny][nx] == c) {
paint(m, nx, ny, nc, c);
}
}
}
Mat get_next(const Mat& m, char c)
{
Mat res = m;
memset(visited, 0, sizeof(visited));
paint(res, 0, 0, c, m[0][0]);
return res;
}
bool reach(Mat& m)
{
char c = m[0][0];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (m[i][j] != c) {
return 0;
}
}
}
return 1;
}
int bfs()
{
queue<Mat> Q;
Q.push(M);
map<Mat, int> d;
d[M] = 0;
while (!Q.empty()) {
Mat m = Q.front(); Q.pop();
if (reach(m)) return d[m];
for (int i = 0; i < 3; i++) {
if (m[0][0] == col[i]) continue;
Mat next = get_next(m, col[i]);
if (d.count(next) == 0) {
d[next] = d[m] + 1;
Q.push(next);
}
}
}
return -1;
}
int main()
{
while (cin >> W >> H, W > 0) {
M.resize(H);
for (int i = 0; i < H; i++) {
M[i].resize(W);
for (int j = 0; j < W; j++) {
cin >> M[i][j];
}
}
cout << bfs() << endl;
}
return 0;
} | a.cc: In function 'Mat get_next(const Mat&, char)':
a.cc:44:5: error: 'memset' was not declared in this scope
44 | memset(visited, 0, sizeof(visited));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <map>
+++ |+#include <cstring>
5 |
|
s074444681 | p00243 | C++ | #include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1 << 25;
int ans;
int b[10][10];
int W, H;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
bool in(int x, int y) {
return 0 <= x && x < W && 0 <= y && y < H;
}
void copy_board(int dst[10][10], int src[10][10]) {
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
dst[i][j] = src[i][j];
}
}
}
typedef pair<int, int> P;
int vis[10][10];
void color(int b[10][10], int c) {
memset(vis, 0, sizeof vis);
int cc = b[0][0];
queue<P> q;
q.push({ 0, 0 });
b[0][0] = c;
while(q.size()) {
int x = q.front().first, y = q.front().second;
q.pop();
for(int k = 0; k < 4; k++) {
int nx = x + dx[k], ny = y + dy[k];
if(in(nx, ny) && b[ny][nx] == cc && !vis[ny][nx]) {
vis[ny][nx] = 1;
b[ny][nx] = c;
q.push({ nx, ny });
}
}
}
}
void dfs(int n) {
if(n == 20) return;
for(int c = 0; c < 3; c++) {
int cnt = 0;
for(int i = 0; i < H; i++) {
cnt += count(b[i], b[i] + W, c);
}
if(cnt == H * W) {
ans = min(ans, n);
return;
}
}
int tmp[10][10];
copy_board(tmp, b);
for(int i = 0; i < 3; i++) {
copy_board(b, tmp);
if(b[0][0] != i) {
color(b, i);
dfs(n + 1);
}
}
copy_board(b, tmp);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while(cin >> W >> H, W) {
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
char c;
cin >> c;
if(c == 'R') b[i][j] = 0;
if(c == 'G') b[i][j] = 1;
if(c == 'B') b[i][j] = 2;
}
}
ans = INF;
dfs(0);
cout << ans << endl;
}
} | a.cc: In function 'void color(int (*)[10], int)':
a.cc:28:9: error: 'memset' was not declared in this scope
28 | memset(vis, 0, sizeof vis);
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 | using namespace std;
|
s834942211 | p00243 | C++ | // Filling Game
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> Pos;
#define NONE -1
struct Data{
  vector< vector<char> >panel;
  int depth;
  Data(){}
  Data(vector< vector<char> >v, int n){panel=v;depth=n;}
};
int h,w;
char color[3]={'R','G','B'};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
vector< vector<char> > change(vector< vector<char> > panel, char after)
{
  char pre=panel[1][1];
  vector< vector<char> > visited(h+2,vector<char>(w+2,0));
  queue<Pos> q;
  q.push(Pos(1,1));
  visited[1][1]=1;
  while(!q.empty()){
    Pos p=q.front();q.pop();
    panel[p.first][p.second]=after;
    for(int i=0;i<4;i++){
      Pos next=p;
      next.first+=dy[i];
      next.second+=dx[i];
      if(visited[next.first][next.second])continue;
      if(panel[next.first][next.second]!=pre)continue;
      q.push(next);
      visited[next.first][next.second]=1;
    }
  }
  return panel;
}
bool ok(vector< vector<char> > panel){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(panel[i+1][j+1]!=panel[1][1])return false;
    }
  }
  return true;
}
int solve(vector< vector<char> > panel)
{
  int depth=0;
  queue<Data>q;
  q.push(Data(panel,0));
  while(!q.empty()){
    Data now=q.front();q.pop();
    Data next;
    next.depth=now.depth+1;
    for(int c=0;c<3;c++){
      if(now.panel[1][1]==color[c])continue;
      next.panel=change(now.panel,color[c]);
      if(ok(next.panel))return next.depth;
      q.push(next);
    }
  }
  return -1;
}
int main()
{
  while(cin>>w>>h,w|h){
    vector< vector<char> >panel(h+2,vector<char>(w+2,NONE));
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)scanf(" %1c", &panel[i+1][j+1]);
    cout<<solve(panel)<<endl;
  }
} | a.cc:12:2: error: stray '#' in program
12 |   vector< vector<char> >panel;
| ^
a.cc:13:2: error: stray '#' in program
13 |   int depth;
| ^
a.cc:14:2: error: stray '#' in program
14 |   Data(){}
| ^
a.cc:15:2: error: stray '#' in program
15 |   Data(vector< vector<char> >v, int n){panel=v;depth=n;}
| ^
a.cc:25:2: error: stray '#' in program
25 |   char pre=panel[1][1];
| ^
a.cc:26:2: error: stray '#' in program
26 |   vector< vector<char> > visited(h+2,vector<char>(w+2,0));
| ^
a.cc:27:2: error: stray '#' in program
27 |   queue<Pos> q;
| ^
a.cc:28:2: error: stray '#' in program
28 |   q.push(Pos(1,1));
| ^
a.cc:29:2: error: stray '#' in program
29 |   visited[1][1]=1;
| ^
a.cc:30:2: error: stray '#' in program
30 |   while(!q.empty()){
| ^
a.cc:31:2: error: stray '#' in program
31 |     Pos p=q.front();q.pop();
| ^
a.cc:31:9: error: stray '#' in program
31 |     Pos p=q.front();q.pop();
| ^
a.cc:32:2: error: stray '#' in program
32 |     panel[p.first][p.second]=after;
| ^
a.cc:32:9: error: stray '#' in program
32 |     panel[p.first][p.second]=after;
| ^
a.cc:33:2: error: stray '#' in program
33 |     for(int i=0;i<4;i++){
| ^
a.cc:33:9: error: stray '#' in program
33 |     for(int i=0;i<4;i++){
| ^
a.cc:34:2: error: stray '#' in program
34 |       Pos next=p;
| ^
a.cc:34:9: error: stray '#' in program
34 |       Pos next=p;
| ^
a.cc:34:16: error: stray '#' in program
34 |       Pos next=p;
| ^
a.cc:35:2: error: stray '#' in program
35 |       next.first+=dy[i];
| ^
a.cc:35:9: error: stray '#' in program
35 |       next.first+=dy[i];
| ^
a.cc:35:16: error: stray '#' in program
35 |       next.first+=dy[i];
| ^
a.cc:36:2: error: stray '#' in program
36 |       next.second+=dx[i];
| ^
a.cc:36:9: error: stray '#' in program
36 |       next.second+=dx[i];
| ^
a.cc:36:16: error: stray '#' in program
36 |       next.second+=dx[i];
| ^
a.cc:37:2: error: stray '#' in program
37 |       if(visited[next.first][next.second])continue;
| ^
a.cc:37:9: error: stray '#' in program
37 |       if(visited[next.first][next.second])continue;
| ^
a.cc:37:16: error: stray '#' in program
37 |       if(visited[next.first][next.second])continue;
| ^
a.cc:38:2: error: stray '#' in program
38 |       if(panel[next.first][next.second]!=pre)continue;
| ^
a.cc:38:9: error: stray '#' in program
38 |       if(panel[next.first][next.second]!=pre)continue;
| ^
a.cc:38:16: error: stray '#' in program
38 |       if(panel[next.first][next.second]!=pre)continue;
| ^
a.cc:39:2: error: stray '#' in program
39 |       q.push(next);
| ^
a.cc:39:9: error: stray '#' in program
39 |       q.push(next);
| ^
a.cc:39:16: error: stray '#' in program
39 |       q.push(next);
| ^
a.cc:40:2: error: stray '#' in program
40 |       visited[next.first][next.second]=1;
| ^
a.cc:40:9: error: stray '#' in program
40 |       visited[next.first][next.second]=1;
| ^
a.cc:40:16: error: stray '#' in program
40 |       visited[next.first][next.second]=1;
| ^
a.cc:41:2: error: stray '#' in program
41 |     }
| ^
a.cc:41:9: error: stray '#' in program
41 |     }
| ^
a.cc:42:2: error: stray '#' in program
42 |   }
| ^
a.cc:43:2: error: stray '#' in program
43 |   return panel;
| ^
a.cc:47:2: error: stray '#' in program
47 |   for(int i=0;i<h;i++){
| ^
a.cc:48:2: error: stray '#' in program
48 |     for(int j=0;j<w;j++){
| ^
a.cc:48:9: error: stray '#' in program
48 |     for(int j=0;j<w;j++){
| ^
a.cc:49:2: error: stray '#' in program
49 |       if(panel[i+1][j+1]!=panel[1][1])return false;
| ^
a.cc:49:9: error: stray '#' in program
49 |       if(panel[i+1][j+1]!=panel[1][1])return false;
| ^
a.cc:49:16: error: stray '#' in program
49 |       if(panel[i+1][j+1]!=panel[1][1])return false;
| ^
a.cc:50:2: error: stray '#' in program
50 |     }
| ^
a.cc:50:9: error: stray '#' in program
50 |     }
| ^
a.cc:51:2: error: stray '#' in program
51 |   }
| ^
a.cc:52:2: error: stray '#' in program
52 |   return true;
| ^
a.cc:57:2: error: stray '#' in program
57 |   int depth=0;
| ^
a.cc:58:2: error: stray '#' in program
58 |   queue<Data>q;
| ^
a.cc:59:2: error: stray '#' in program
59 |   q.push(Data(panel,0));
| ^
a.cc:60:2: error: stray '#' in program
60 |   while(!q.empty()){
| ^
a.cc:61:2: error: stray '#' in program
61 |     Data now=q.front();q.pop();
| ^
a.cc:61:9: error: stray '#' in program
61 |     Data now=q.front();q.pop();
| ^
a.cc:62:2: error: stray '#' in program
62 |     Data next;
| ^
a.cc:62:9: error: stray '#' in program
62 |     Data next;
| ^
a.cc:63:2: error: stray '#' in program
63 |     next.depth=now.depth+1;
| ^
a.cc:63:9: error: stray '#' in program
63 |     next.depth=now.depth+1;
| ^
a.cc:64:2: error: stray '#' in program
64 |     for(int c=0;c<3;c++){
| ^
a.cc:64:9: error: stray '#' in program
64 |     for(int c=0;c<3;c++){
| ^
a.cc:65:2: error: stray '#' in program
65 |       if(now.panel[1][1]==color[c])continue;
| ^
a.cc:65:9: error: stray '#' in program
65 |       if(now.panel[1][1]==color[c])continue;
| ^
a.cc:65:16: error: stray '#' in program
65 |       if(now.panel[1][1]==color[c])continue;
| ^
a.cc:66:2: error: stray '#' in program
66 |       next.panel=change(now.panel,color[c]);
| ^
a.cc:66:9: error: stray '#' in program
66 |       next.panel=change(now.panel,color[c]);
| ^
a.cc:66:16: error: stray '#' in program
66 |       next.panel=change(now.panel,color[c]);
| ^
a.cc:67:2: error: stray '#' in program
67 |       if(ok(next.panel))return next.depth;
| ^
a.cc:67:9: error: stray '#' in program
67 |       if(ok(next.panel))return next.depth;
| ^
a.cc:67:16: error: stray '#' in program
67 |       if(ok(next.panel))return next.depth;
| ^
a.cc:68:2: error: stray '#' in program
68 |       q.push(next);
| ^
a.cc:68:9: error: stray '#' in program
68 |       q.push(next);
| ^
a.cc:68:16: error: stray '#' in program
68 |       q.push(next);
| ^
a.cc:69:2: error: stray '#' in program
69 |     }
| ^
a.cc:69:9: error: stray '#' in program
69 |     }
| ^
a.cc:70:2: error: stray '#' in program
70 |   }
| ^
a.cc:71:2: error: stray '#' in program
71 |   return -1;
| ^
a.cc:76:2: error: stray '#' in program
76 |   while(cin>>w>>h,w|h){
| ^
a.cc:77:2: error: stray '#' in program
77 |     vector< vector<char> >panel(h+2,vector<char>(w+2,NONE));
| ^
a.cc:77:9: error: stray '#' in program
77 |     vector< vector<char> >panel(h+2,vector<char>(w+2,NONE));
| ^
a.cc:78:2: error: stray '#' in program
78 |     for(int i=0;i<h;i++)for(int j=0;j<w;j++)scanf(" %1c", &panel[i+1][j+1]);
| ^
a.cc:78:9: error: stray '#' in program
78 |     for(int i=0;i<h;i++)for(int j=0;j<w;j++)scanf(" %1c", &panel[i+1][j+1]);
| ^
a.cc:80:2: error: stray '#' in program
80 |     cout<<solve(panel)<<endl;
| ^
a.cc:80:9: error: stray '#' in program
80 |     cout<<solve(panel)<<endl;
| ^
a.cc:81:2: error: stray '#' in program
81 |   }
| ^
a.cc:12:3: error: expected unqualified-id before numeric constant
12 |   vector< vector<char> >panel;
| ^~~
a.cc:13:3: error: expected unqualified-id before numeric constant
13 |   int depth;
| ^~~
a.cc:14:3: error: expected unqualified-id before numeric constant
14 |   Data(){}
| ^~~
a.cc:15:3: error: expected unqualified-id before numeric constant
15 |   Data(vector< vector<char> >v, int n){panel=v;depth=n;}
| ^~~
a.cc: In function 'std::vector<std::vector<char> > change(std::vector<std::vector<char> >, char)':
a.cc:25:3: error: lvalue required as unary '&' operand
25 |   char pre=panel[1][1];
| ^~~
a.cc:26:3: error: lvalue required as unary '&' operand
26 |   vector< vector<char> > visited(h+2,vector<char>(w+2,0));
| ^~~
a.cc:27:3: error: lvalue required as unary '&' operand
27 |   queue<Pos> q;
| ^~~
a.cc:28:3: error: lvalue required as unary '&' operand
28 |   q.push(Pos(1,1));
| ^~~
a.cc:29:3: error: lvalue required as unary '&' operand
29 |   visited[1][1]=1;
| ^~~
a.cc:30:3: error: lvalue required as unary '&' operand
30 |   while(!q.empty()){
| ^~~
a.cc:31:3: error: lvalue required as unary '&' operand
31 |   & |
s570106201 | p00243 | C++ | #include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <sstream>
#include <algorithm>
using namespace std;
char bt[10][10];
char ne[10][10];
bool dn[10][10];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int W,H;
void chg(int x,int y,char a,char b){
if( x < 0 || x >= W || y < 0 || y >= H || bt[y][x] != b || dn[y][x]) return;
dn[y][x] = true;
ne[y][x] = a;
for(int i = 0 ; i < 4 ; i++){
chg(x+dx[i],y+dy[i],a,b);
}
}
int ans = 0;
int dfs(int r){
if( r >= ans ){
//cout << r << endl;
return 0;
}
int f = true;
for(int i = 0 ; i < H ; i++){
for(int j = 0 ; j < W ; j++){
if(bt[i][j] != bt[0][0]){
f = false;
goto en;
}
}
}
en:;
if( f ){
ans = r;
return 0;
}
char tmp[10][10];
bool prev[10][10];
memcpy(prev,dn,sizeof(dn));
memcpy(tmp,bt,sizeof(tmp));
for(int i = 0 ; i < 3 ; i++){
memcpy(ne,bt,sizeof(ne));
memset(dn,0,sizeof(dn));
int f = false;
if( "RGB"[i] != bt[0][0] ){
chg(0,0,"RGB"[i],bt[0][0]);
for(int i = 0 ; i < H ; i++){
for(int j = 0 ; j < W ; j++)
if(prev[i][j] != dn[i][j]) f = true;
}
memcpy(bt,ne,sizeof(ne));
if(f)dfs(r+1);
memcpy(bt,tmp,sizeof(tmp));
}
}
}
int main(){
int n;
while(cin >> W >> H && W){
memset(dn,0,sizeof(dn));
for(int i = 0 ; i < H ; i++)
for(int j = 0 ; j < W ; j++)
cin >> bt[i][j];
ans = 1e7;
dfs(0);
cout << ans << endl;
}
} | a.cc: In function 'int dfs(int)':
a.cc:52:9: error: 'memcpy' was not declared in this scope
52 | memcpy(prev,dn,sizeof(dn));
| ^~~~~~
a.cc:8:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
7 | #include <sstream>
+++ |+#include <cstring>
8 | #include <algorithm>
a.cc:56:17: error: 'memset' was not declared in this scope
56 | memset(dn,0,sizeof(dn));
| ^~~~~~
a.cc:56:17: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc: In function 'int main()':
a.cc:73:17: error: 'memset' was not declared in this scope
73 | memset(dn,0,sizeof(dn));
| ^~~~~~
a.cc:73:17: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc: In function 'int dfs(int)':
a.cc:69:1: warning: control reaches end of non-void function [-Wreturn-type]
69 | }
| ^
|
s698126282 | p00243 | C++ | #include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <algorithm>
using namespace std;
char bt[10][10];
char ne[10][10];
bool dn[10][10];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int W,H;
int main(){
int n;
while(cin >> W >> H && W){
memset(dn,0,sizeof(dn));
for(int i = 0 ; i < H ; i++)
for(int j = 0 ; j < W ; j++)
cin >> bt[i][j];
ans = 1e7;
// dfs(0);
cout << ans << endl;
}
} | a.cc: In function 'int main()':
a.cc:28:9: error: 'ans' was not declared in this scope; did you mean 'abs'?
28 | ans = 1e7;
| ^~~
| abs
|
s571482954 | p00243 | C++ | #include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> P;
struct state{
char f[11][11];
int c,l;
state(){}
state(int c,int l):c(c),l(l){};
};
char in[11][11];
state ne;
bool used[11][11];
const int dx[4]={0,0,1,-1};
const int dy[4]={1,-1,0,0};
int n,m;
int res;
void dfs(int next,int prev,int x,int y){
if(x==0 && y==0){
memset(used,false,sizeof(used));
}
ne.f[x][y]=next;
used[x][y]=true;
for(int i=0;i<4;i++){
int nx=x+dx[i],ny=y+dy[i];
if(nx>=0 && nx<n && ny>=0 && ny<m){
if(!used[nx][ny]){
used[nx][ny]=true;
if(ne.f[nx][ny]==next){
}
if(ne.f[nx][ny]==prev){
dfs(next,prev,nx,ny);
}
}
}
}
}
void cnt(int prev,int x,int y){
if(x==0 && y==0){
ne.l=0;
memset(used,false,sizeof(used));
}
ne.l++;
used[x][y]=true;
for(int i=0;i<4;i++){
int nx=x+dx[i],ny=y+dy[i];
if(nx>=0 && nx<n && ny>=0 && ny<m){
if(!used[nx][ny]){
used[nx][ny]=true;
if(ne.f[nx][ny]==prev){
cnt(prev,nx,ny);
}
}
}
}
}
void bfs(state init){
queue<state> que;
map<state, bool> V;
res=50;
V[init]= true;
que.push(init);
while(que.size()){
state p=que.front();
que.pop();
ne.c=p.c+1;
for(int i=0;i<=2;i++){
memcpy(ne.f,p.f,sizeof(ne.f));
dfs(i,ne.f[0][0],0,0);
cnt(ne.f[0][0],0,0);
//if(!V[ne.f]){
if(ne.l==n*m)res=min(res,p.c+1);
else if(ne.l>p.l)que.push(ne);
// V[ne.f]=true;
//}
}
}
}
int main(void){
while(1){
res=100;
scanf("%d%d\n",&n,&m);
if(n==0 && m==0)break;
state init=state(0,1);
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin >> in[j][i];
if(in[j][i]=='R')init.f[j][i]=0;
if(in[j][i]=='G')init.f[j][i]=1;
if(in[j][i]=='B')init.f[j][i]=2;
}
}
memcpy(ne.f,init.f,sizeof(ne.f));
cnt(ne.f[0][0],0,0);
if(ne.l==n*m)printf("0\n");
else{
bfs(init);
printf("%d\n",res);
}
}
return 0;
} | In file included from /usr/include/c++/14/string:49,
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_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = state]':
/usr/include/c++/14/bits/stl_map.h:511:32: required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = state; _Tp = bool; _Compare = std::less<state>; _Alloc = std::allocator<std::pair<const state, bool> >; mapped_type = bool; key_type = state]'
511 | if (__i == end() || key_comp()(__k, (*__i).first))
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
a.cc:68:8: required from here
68 | V[init]= true;
| ^
/usr/include/c++/14/bits/stl_function.h:405:20: error: no match for 'operator<' (operand types are 'const state' and 'const state')
405 | { return __x < __y; }
| ~~~~^~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
448 | operator<(const reverse_iterator<_Iterator>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note: 'const state' is not derived from 'const std::reverse_iterator<_Iterator>'
405 | { return __x < __y; }
| ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
493 | operator<(const reverse_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note: 'const state' is not derived from 'const std::reverse_iterator<_Iterator>'
405 | { return __x < __y; }
| ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
1694 | operator<(const move_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note: 'const state' is not derived from 'const std::move_iterator<_IteratorL>'
405 | { return __x < __y; }
| ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
1760 | operator<(const move_iterator<_Iterator>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note: 'const state' is not derived from 'const std::move_iterator<_IteratorL>'
405 | { return __x < __y; }
| ~~~~^~~~~
|
s261522136 | p00243 | C++ | #include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
typedef unsigned long long UInt64;
typedef long long Int64;
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
int ans=INF;
int x,y;
inline int change(string ss)
{
if(ss=="R") return 0;
if(ss=="G") return 1;
if(ss=="B") return 2;
}
inline bool check(vector<vector<int> > tile)
{
rep(i,tile.size())
{
rep(j,tile[i].size())
{
if(tile[0][0]!=tile[i][j])
return false;
}
}
return true;
}
void f(vector<vector<int> > &tile,int color)
{
//x,y
queue<P> que;
int oldcolor=tile[0][0];
tile[0][0]=color;
que.push(P(0,0));
while(que.size())
{
P p = que.front(); que.pop();
rep(i,4)
{
int nx=p.fr+dx[i];
int ny=p.sc+dy[i];
if(0<=nx&&nx<x&&0<=ny&&ny<y&&tile[nx][ny]==oldcolor)
{
tile[nx][ny]=color;
que.push(P(nx,ny));
}
}
}
}
void dfs(vector<vector<int> > tile,int depth)
{
if(check(tile))
{
ans=min(ans,depth);
return;
}
//最大でも18手を越えないらしい
if(depth==18) return;
vector<vector<int> > tile1=tile;
vector<vector<int> > tile2=tile;
if(tile[0][0]==0)
{
f(tile1,1);
f(tile2,2);
}
if(tile[0][0]==1)
{
f(tile1,0);
f(tile2,2);
}
if(tile[0][0]==2)
{
f(tile1,1);
f(tile2,0);
}
dfs(tile1,depth+1);
dfs(tile2,depth+1);
}
void solve()
{
vector<vector<int> > tile;
tile.reserve(10);
rep(i,x)
{
vector<int> vec.reserve(10);
rep(j,y)
{
string c;
cin>>c;
vec.pb(change(c));
}
tile.pb(vec);
}
dfs(tile,0);
}
int main()
{
while(cin>>x>>y)
{
swap(x,y);
if(x==0&&y==0)
return 0;
solve();
cout<<ans<<endl;
ans=INF;
}
return 0;
} | a.cc: In function 'void solve()':
a.cc:132:32: error: expected initializer before '.' token
132 | vector<int> vec.reserve(10);
| ^
a.cc:137:25: error: 'vec' was not declared in this scope
137 | vec.pb(change(c));
| ^~~
a.cc:139:25: error: 'vec' was not declared in this scope
139 | tile.pb(vec);
| ^~~
a.cc:22:25: note: in definition of macro 'pb'
22 | #define pb(e) push_back(e)
| ^
|
s580901323 | p00243 | C++ | #include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
typedef pair<int, int> P;
struct State {
int turn;
char board[10][10];
};
int main() {
while(true) {
int X, Y;
cin >> X >> Y;
if(X == 0 && Y == 0) break;
char board[10][10];
for(int i = 0; i < Y; i++) {
for(int j = 0; j < X; j++) {
char c; cin >> c;
if(c == 'R') board[i][j] = 0;
if(c == 'G') board[i][j] = 1;
if(c == 'B') board[i][j] = 2;
}
}
State S;
S.turn = 0;
memcpy(S.board, board, sizeof(board));
queue<State> Q;
Q.push(S);
int res;
while(!Q.empty()) {
State s = Q.front(); Q.pop();
bool ok = true;
for(int i = 0; i < Y; i++) {
for(int j = 0; j < X; j++) {
if(s.board[i][j] != s.board[0][0]) {
ok = false;
break;
}
}
}
if(ok) {
res = s.turn;
break;
}
for(char c = 0; c < 3; c++) {
if(s.board[0][0] == c) continue;
memcpy(S.board, s.board, sizeof(s.board));
queue<P> Q2;
Q2.emplace(0, 0);
char prev = S.board[0][0];
S.board[0][0] = c;
while(!Q2.empty()) {
P p = Q2.front(); Q2.pop();
for(int i = 0; i < 4; i++) {
const int dy[4] = { 0, -1, 0, 1 };
const int dx[4] = { 1, 0, -1, 0 };
int ny = p.first + dy[i];
int nx = p.second + dx[i];
if(0 <= ny && ny < Y && 0 <= nx && nx < X && S.board[ny][nx] == prev) {
S.board[ny][nx] = c;
Q2.emplace(ny, nx);
}
}
}
S.turn = s.turn + 1;
Q.push(S);
}
}
cout << res << endl;
}
} | a.cc: In function 'int main()':
a.cc:30:5: error: 'memcpy' was not declared in this scope
30 | memcpy(S.board, board, sizeof(board));
| ^~~~~~
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 | using namespace std;
|
s202250314 | p00243 | C++ | #include<iostream>
#include<memory>
int field_x, field_y;
int start;
int color;
int res = 10;
bool check(int field[10][10]){
int r = 0, g = 0, b = 0;
for (int i = 0; i < field_y; i++){
for (int j = 0; j < field_x; j++){
field[i][j] == 0 ? r++ : field[i][j] == 1 ? g++ : b++;
}
}
int a = field_x*field_y;
if (r == a || g == a || b == a)return true;
return false;
}
void bfs(int(&field)[10][10], int x, int y){
field[y][x] = color;
if (x + 1 < field_x && field[y][x + 1] == start)bfs(field, x + 1, y);
if (x - 1 > 0 && field[y][x - 1] == start)bfs(field, x - 1, y);
if (y + 1 < field_y && field[y + 1][x] == start)bfs(field, x, y + 1);
if (y - 1 > 0 && field[y - 1][x] == start)bfs(field, x, y - 1);
}
void calc(int field[10][10], int count){
if (count > res)return;
for (int i = 0; i < 3; i++){
start = field[0][0];
color = i;
if (start == color)continue;
int copy_field[10][10];
std::memcpy(copy_field, field, sizeof(copy_field));
bfs(copy_field, 0, 0);
if (check(copy_field))res = count;
else calc(copy_field, count + 1);
}
}
int main(){
while (std::cin >> field_x >> field_y, field_x || field_y){
int field[10][10];
for (int i = 0; i < field_y; i++){
for (int j = 0; j < field_x; j++){
char c;
std::cin >> c;
c == 'R' ? field[i][j] = 0 : c == 'G' ? field[i][j] = 1 : field[i][j] = 2;
}
}
calc(field, 1);
std::cout << res << std::endl;
res = 10;
}
return 0;
} | a.cc: In function 'void calc(int (*)[10], int)':
a.cc:46:22: error: 'memcpy' is not a member of 'std'; did you mean 'wmemcpy'?
46 | std::memcpy(copy_field, field, sizeof(copy_field));
| ^~~~~~
| wmemcpy
|
s380453241 | p00243 | C++ | #include<iostream>
#include<memory>
int field_x, field_y;
int start;
int color;
int res = 10;
bool check(int field[10][10]){
int r = 0, g = 0, b = 0;
for (int i = 0; i < field_y; i++){
for (int j = 0; j < field_x; j++){
field[i][j] == 0 ? r++ : field[i][j] == 1 ? g++ : b++;
}
}
int a = field_x*field_y;
if (r == a || g == a || b == a)return true;
return false;
}
void bfs(int(&field)[10][10], int x, int y){
field[y][x] = color;
if (x + 1 < field_x && field[y][x + 1] == start)bfs(field, x + 1, y);
if (x - 1 > 0 && field[y][x - 1] == start)bfs(field, x - 1, y);
if (y + 1 < field_y && field[y + 1][x] == start)bfs(field, x, y + 1);
if (y - 1 > 0 && field[y - 1][x] == start)bfs(field, x, y - 1);
}
void calc(int field[10][10], int count){
if (count > res)return;
for (int i = 0; i < 3; i++){
start = field[0][0];
color = i;
if (start == color)continue;
int copy_field[10][10];
memcpy(copy_field, field, sizeof(copy_field));
bfs(copy_field, 0, 0);
if (check(copy_field))res = count;
else calc(copy_field, count + 1);
}
}
int main(){
while (std::cin >> field_x >> field_y, field_x || field_y){
int field[10][10];
for (int i = 0; i < field_y; i++){
for (int j = 0; j < field_x; j++){
char c;
std::cin >> c;
c == 'R' ? field[i][j] = 0 : c == 'G' ? field[i][j] = 1 : field[i][j] = 2;
}
}
calc(field, 1);
std::cout << res << std::endl;
res = 10;
}
return 0;
} | a.cc: In function 'void calc(int (*)[10], int)':
a.cc:46:17: error: 'memcpy' was not declared in this scope
46 | memcpy(copy_field, field, sizeof(copy_field));
| ^~~~~~
a.cc:3:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<memory>
+++ |+#include <cstring>
3 |
|
s366819344 | p00244 | Java | #include<iostream>
#include<queue>
#include<vector>
#include<utility>
#include<functional>
using namespace std;
typedef pair<int, int> P;
struct Edge
{
int cost, to, f;
Edge(int c, int t){cost = c, to = t;}
};
int E, V, d[10000];
vector<Edge> edge[10000];
priority_queue<P, vector<P>, greater<P>> q;
int main()
{
loop:
for(int i = 0; i < 10000; i++)
edge[i].clear();
for(int i = 0; i < 10000; i++)
d[i] = 100000000;
q = priority_queue<P, vector<P>, greater<P>>();
cin >> V >> E;
if(!V)
return 0;
for(int i = 0; i < E; i++)
{
int a, b, c;
cin >> a >> b >> c;
a--, b--;
edge[a].push_back(Edge(c, b));
edge[b].push_back(Edge(c, a));
edge[a + V].push_back(Edge(c, b + V));
edge[b + V].push_back(Edge(c, a + V));
}
for(int i = 0; i < V; i++)
for(const auto& v1 : edge[i])
for(const auto& v2 : edge[v1.to])
if(v2.to != i)
edge[i].push_back(Edge(0, v2.to + V));
q.push(make_pair(0, 0));
d[0] = 0;
while(!q.empty())
{
auto p = q.top(); q.pop();
int c = p.first, v = p.second;
if(d[v] < c)
continue;
for(const Edge& e : edge[v])
{
if(d[e.to] > c + e.cost)
q.push(make_pair(d[e.to] = c + e.cost, e.to));
}
}
cout << min(d[V - 1], d[V * 2 - 1]) << endl;
goto loop;
} | Main.java:1: error: illegal character: '#'
#include<iostream>
^
Main.java:2: error: illegal character: '#'
#include<queue>
^
Main.java:3: error: illegal character: '#'
#include<vector>
^
Main.java:4: error: illegal character: '#'
#include<utility>
^
Main.java:5: error: illegal character: '#'
#include<functional>
^
Main.java:8: error: class, interface, enum, or record expected
typedef pair<int, int> P;
^
Main.java:9: error: class, interface, enum, or record expected
struct Edge
^
Main.java:12: error: class, interface, enum, or record expected
Edge(int c, int t){cost = c, to = t;}
^
Main.java:12: error: class, interface, enum, or record expected
Edge(int c, int t){cost = c, to = t;}
^
Main.java:15: error: class, interface, enum, or record expected
int E, V, d[10000];
^
Main.java:16: error: class, interface, enum, or record expected
vector<Edge> edge[10000];
^
Main.java:17: error: unnamed classes are a preview feature and are disabled by default.
priority_queue<P, vector<P>, greater<P>> q;
^
(use --enable-preview to enable unnamed classes)
Main.java:26: error: not a statement
q = priority_queue<P, vector<P>, greater<P>>();
^
Main.java:26: error: not a statement
q = priority_queue<P, vector<P>, greater<P>>();
^
Main.java:27: error: not a statement
cin >> V >> E;
^
Main.java:33: error: not a statement
cin >> a >> b >> c;
^
Main.java:41: error: not a statement
for(const auto& v1 : edge[i])
^
Main.java:41: error: not a statement
for(const auto& v1 : edge[i])
^
Main.java:42: error: not a statement
for(const auto& v2 : edge[v1.to])
^
Main.java:42: error: not a statement
for(const auto& v2 : edge[v1.to])
^
Main.java:54: error: not a statement
for(const Edge& e : edge[v])
^
Main.java:54: error: not a statement
for(const Edge& e : edge[v])
^
Main.java:60: error: not a statement
cout << min(d[V - 1], d[V * 2 - 1]) << endl;
^
Main.java:61: error: not a statement
goto loop;
^
Main.java:26: error: ';' expected
q = priority_queue<P, vector<P>, greater<P>>();
^
Main.java:26: error: ';' expected
q = priority_queue<P, vector<P>, greater<P>>();
^
Main.java:26: error: ';' expected
q = priority_queue<P, vector<P>, greater<P>>();
^
Main.java:34: error: ';' expected
a--, b--;
^
Main.java:41: error: illegal start of expression
for(const auto& v1 : edge[i])
^
Main.java:41: error: ';' expected
for(const auto& v1 : edge[i])
^
Main.java:41: error: ';' expected
for(const auto& v1 : edge[i])
^
Main.java:42: error: illegal start of expression
for(const auto& v2 : edge[v1.to])
^
Main.java:42: error: ';' expected
for(const auto& v2 : edge[v1.to])
^
Main.java:42: error: ';' expected
for(const auto& v2 : edge[v1.to])
^
Main.java:54: error: illegal start of expression
for(const Edge& e : edge[v])
^
Main.java:54: error: ';' expected
for(const Edge& e : edge[v])
^
Main.java:54: error: ';' expected
for(const Edge& e : edge[v])
^
Main.java:61: error: illegal start of expression
goto loop;
^
38 errors
|
s542276912 | p00244 | C | #include <cstdio>
#include <cstring>
#include <vector>
#define MAX_N (100)
#define INF (100000000)
using namespace std;
typedef struct {
int to;
int cost;
} Edge;
vector<Edge> G[MAX_N];
int W[MAX_N][MAX_N];
int ans;
int n, m;
void getMin(int V, int cost, int left, bool used[MAX_N])
{
if (cost >= ans){
return;
}
if (V == n - 1){
if ((left == 2 || left == 0) && ans > cost){
ans = cost;
}
return;
}
used[V] = true;
if (left == 2){
for (int i = 0; i < G[V].size(); i++){
if (used[G[V][i].to] == false){
getMin(G[V][i].to, cost + G[V][i].cost, left, used);
getMin(G[V][i].to, cost, left - 1, used);
}
}
}
if (left == 1){
for (int i = 0; i < G[V].size(); i++){
if (used[G[V][i].to] == false){
getMin(G[V][i].to, cost, left - 1, used);
}
}
}
if (left == 0){
getMin(n - 1, cost + W[V][n - 1], 0, used);
}
used[V] = false;
return;
}
int main()
{
int a, b, c;
Edge in;
while (1){
scanf("%d %d", &n, &m);
if (n + m == 0){
break;
}
for (int i = 0; i < n; i++){
G[i].clear();
}
for (int i = 0; i < n; i++){
fill(W[i], W[i] + n, INF);
W[i][i] = 0;
}
for (int i = 0; i < m; i++){
scanf("%d %d %d", &a, &b, &c);
in.to = --a;
in.cost = c;
G[--b].push_back(in);
in.to = b;
G[a].push_back(in);
W[a][b] = W[b][a] = c;
}
for (int k = 0; k < n; k++){
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
W[i][j] = min(W[i][j], W[i][k] + W[k][j]);
}
}
}
bool used[MAX_N];
fill(used, used + MAX_N, false);
ans = INF;
getMin(0, 0, 2, used);
printf("%d\n", ans);
}
return (0);
} | main.c:1:10: fatal error: cstdio: No such file or directory
1 | #include <cstdio>
| ^~~~~~~~
compilation terminated.
|
s789288594 | p00244 | C++ | #include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, int> lli;
struct edge { int v; ll w; };
vector<edge> G[100];
ll d1[100], d2[100];
void dijkstra(int n, vector<edge> G[], int s, ll d[]) {
fill(d, d + n, LONG_MAX); d[s] = 0;
priority_queue<lli, vector<lli>, greater<lli> > q;
q.push(lli(0, s));
while (!q.empty()) {
lli p = q.top(); q.pop();
int u = p.second;
if (p.first > d[u]) continue;
for (int j = 0; j < G[u].size(); j++) {
edge e = G[u][j];
if (d[e.v] > d[u] + e.w) {
d[e.v] = d[u] + e.w;
q.push(lli(d[e.v], e.v));
}
}
}
}
int main() {
for (;;) {
int n, m; scanf("%d%d", &n, &m);
if (n == 0) break;
for (int u = 0; u < n; u++) G[u].clear();
for (; m > 0; m--) {
int a, b, c; scanf("%d%d%d", &a, &b, &c);
edge e1 = {b - 1, c}; G[a - 1].push_back(e1);
edge e2 = {a - 1, c}; G[b - 1].push_back(e2);
}
dijkstra(n, G, 0, d1);
dijkstra(n, G, n - 1, d2);
ll ans = LONG_MAX;
for (int u = 0; u < n; u++)
for (int i = 0; i < G[u].size(); i++)
for (int j = 0; j < G[u].size(); j++) {
ll v1 = G[u][i].v, v2 = G[u][j].v;
if (d1[v1] == LONG_MAX || d2[v2] == LONG_MAX) continue;
ans = min(ans, d1[v1] + d2[v2]);
}
printf("%d\n", ans);
}
}
#include <climits>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, int> lli;
struct edge { int v; ll w; };
vector<edge> G[100];
ll d1[100], d2[100];
void dijkstra(int n, vector<edge> G[], int s, ll d[]) {
fill(d, d + n, LONG_MAX); d[s] = 0;
priority_queue<lli, vector<lli>, greater<lli>> q;
q.push(lli(0, s));
while (!q.empty()) {
lli p = q.top(); q.pop();
int u = p.second;
if (p.first > d[u]) continue;
for (int j = 0; j < G[u].size(); j++) {
edge e = G[u][j];
if (d[e.v] > d[u] + e.w) {
d[e.v] = d[u] + e.w;
q.push(lli(d[e.v], e.v));
}
}
}
}
int main() {
for (;;) {
int n, m; scanf("%d%d", &n, &m);
if (n == 0) break;
for (int u = 0; u < n; u++) G[u].clear();
for (; m > 0; m--) {
int a, b, c; scanf("%d%d%d", &a, &b, &c);
edge e1 = {b - 1, c}; G[a - 1].push_back(e1);
edge e2 = {a - 1, c}; G[b - 1].push_back(e2);
}
dijkstra(n, G, 0, d1);
dijkstra(n, G, n - 1, d2);
ll ans = LONG_MAX;
for (int u = 0; u < n; u++)
for (int i = 0; i < G[u].size(); i++)
for (int j = 0; j < G[u].size(); j++) {
ll v1 = G[u][i].v, v2 = G[u][j].v;
if (d1[v1] == LONG_MAX || d2[v2] == LONG_MAX) continue;
ans = min(ans, d1[v1] + d2[v2]);
}
printf("%d\n", ans);
}
} | a.cc:5:19: warning: extra tokens at end of #include directive
5 | #include <cstring>#include <algorithm>
| ^
a.cc:72:8: error: redefinition of 'struct edge'
72 | struct edge { int v; ll w; };
| ^~~~
a.cc:18:8: note: previous definition of 'struct edge'
18 | struct edge { int v; ll w; };
| ^~~~
a.cc:74:14: error: redefinition of 'std::vector<edge> G [100]'
74 | vector<edge> G[100];
| ^
a.cc:20:14: note: 'std::vector<edge> G [100]' previously declared here
20 | vector<edge> G[100];
| ^
a.cc:75:4: error: redefinition of 'll d1 [100]'
75 | ll d1[100], d2[100];
| ^~
a.cc:21:4: note: 'll d1 [100]' previously declared here
21 | ll d1[100], d2[100];
| ^~
a.cc:75:13: error: redefinition of 'll d2 [100]'
75 | ll d1[100], d2[100];
| ^~
a.cc:21:13: note: 'll d2 [100]' previously declared here
21 | ll d1[100], d2[100];
| ^~
a.cc:77:6: error: redefinition of 'void dijkstra(int, std::vector<edge>*, int, ll*)'
77 | void dijkstra(int n, vector<edge> G[], int s, ll d[]) {
| ^~~~~~~~
a.cc:23:6: note: 'void dijkstra(int, std::vector<edge>*, int, ll*)' previously defined here
23 | void dijkstra(int n, vector<edge> G[], int s, ll d[]) {
| ^~~~~~~~
a.cc:95:5: error: redefinition of 'int main()'
95 | int main() {
| ^~~~
a.cc:41:5: note: 'int main()' previously defined here
41 | int main() {
| ^~~~
|
s745668693 | p00244 | C++ | #include<iostream>
#include<queue>
#include<vector>
#include<utility>
#include<functional>
using namespace std;
typedef pair<int, int> P;
struct Edge
{
int cost, to, f;
Edge(int c, int t){cost = c, to = t}
};
int E, V, d[1000];
vector<Edge> edge[1000];
int main()
{
loop:
for(int i = 0; i < 1000; i++)
edge[i].clear();
for(int i = 0; i < 100; i++)
d[i] = 100000000;
cin >> V >> E;
if(!V)
return 0;
for(int i = 0; i < E; i++)
{
int a, b, c;
cin >> a >> b >> c;
a--, b--;
edge[a].push_back(Edge(c, b));
edge[b].push_back(Edge(c, a));
edge[a + V].push_back(Edge(c, b + V));
edge[b + V].push_back(Edge(c, a + V));
}
for(int i = 0; i < V; i++)
for(const auto& v1 : edge[i])
for(const auto& v2 : edge[v1.to])
if(v2.to != i)
edge[i].push_back(Edge(0, v2.to + V));
priority_queue<P, vector<P>, greater<P>> q;
q.push(make_pair(0, 0));
while(!q.empty())
{
auto p = q.top(); q.pop();
int c = p.first, v = p.second;
if(d[v] < c)
continue;
for(const Edge& e : edge[v])
{
if(d[e.to] > d[v] + e.cost)
q.push(make_pair(d[e.to] = d[v] + e.cost, e.to));
}
}
cout << min(d[V - 1], d[V * 2 - 1]) << endl;
goto loop;
} | a.cc: In constructor 'Edge::Edge(int, int)':
a.cc:12:38: error: expected ';' before '}' token
12 | Edge(int c, int t){cost = c, to = t}
| ^
|
s548351473 | p00244 | C++ | #include<iostream>
#include<queue>
#include<vector>
#include<utility>
#include<functional>
using namespace std;
typedef pair<int, int> P;
struct Edge
{
int cost, to, f;
Edge(int c, int t){cost = c, to = t}
};
int E, V, d[1000];
vector<Edge> edge[1000];
int main()
{
loop:
for(int i = 0; i < 1000; i++)
edge[i].clear();
for(int i = 0; i < 100; i++)
d[i] = 100000000;
cin >> V >> E;
if(!V)
return 0;
for(int i = 0; i < E; i++)
{
int a, b, c;
cin >> a >> b >> c;
a--, b--;
edge[a].push_back(Edge(c, b));
edge[b].push_back(Edge(c, a));
edge[a + V].push_back(Edge(c, b + V));
edge[b + V].push_back(Edge(c, a + V));
}
for(int i = 0; i < V; i++)
for(const auto& v1 : edge[i])
for(const auto& v2 : edge[v1.to])
if(v2.to != i)
edge[i].push_back(Edge(0, v2.to + V));
priority_queue<P, vector<P>, greater<P>> q;
q.push(make_pair(0, 0));
while(!q.empty())
{
auto p = q.top(); q.pop();
int c = p.first, v = p.second;
if(d[v] < c)
continue;
for(const Edge& e : edge[v])
{
if(d[e.to] > d[v] + e.cost)
q.push(make_pair(d[e.to] = d[v] + e.cost, e.to));
}
}
cout << min(d[V - 1], d[V * 2 - 1]) << endl;
goto loop;
} | a.cc: In constructor 'Edge::Edge(int, int)':
a.cc:12:38: error: expected ';' before '}' token
12 | Edge(int c, int t){cost = c, to = t}
| ^
|
s749664137 | p00244 | C++ | #include<iostream>
#include<algorithm>
using namespace std;
int n,m,mm;
int a[302],b[302],c[302],mn[302];
int ans;
int slv();
int main(){
while(1){
cin>>n>>m;
if(n==0 && m==0)break;
mm=m;
ans=2000000;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
for(int i=2;i<=n;i++)mn[i]=2000000;
for(int i=1;i<=m;i++)cin>>a[i]>>b[i]>>c[i];
mn[1]=0;
slv();
mm++;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[j]==i){
for(int k=1;k<=m;k++){
if(a[k]==b[j]){
a[mm]=i;
b[mm]=b[k];
for(int i=2;i<=n;i++)mn[i]=2000000;
mn[1]=0;
slv();
}
else if(b[k]==b[i]){
a[mm]=i;
b[mm]=a[k];
for(int i=2;i<=n;i++)mn[i]=2000000;
mn[1]=0;
slv();
}
}
}
else if(b[j]==i){
for(int k=1;k<=m;k++){
if(a[k]==a[j]){
a[mm]=i;
b[mm]=b[k];
for(int i=2;i<=n;i++)mn[i]=2000000;
mn[1]=0;
slv();
}
else if(b[k]==a[j]){
a[mm]=i;
b[mm]=a[k];
for(int i=2;i<=n;i++)mn[i]=2000000;
mn[1]=0;
slv();
}
}
}
}
}
cout<<ans<<endl;
}
}
int slv(){
for(int cnt=0;cnt<10;cnt++){
for(int i=1;i<=n;i++){
for(int j=1;j<=mm;j++){
if(a[j]==i){
mn[b[j]]=min(mn[b[j]],mn[a[j]]+c[j]);
}
else if(b[j]==i){
mn[a[j]]=min(mn[a[j]],mn[b[j]]+c[j]);
}
}
}
}
ans=min(ans,mn[n]);
} | a.cc: In function 'int main()':
a.cc:15:5: error: 'memset' was not declared in this scope
15 | memset(a,0,sizeof(a));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<algorithm>
+++ |+#include <cstring>
3 | using namespace std;
a.cc: In function 'int slv()':
a.cc:83:1: warning: no return statement in function returning non-void [-Wreturn-type]
83 | }
| ^
|
s594932211 | p00244 | C++ | #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define NUM 2000000000
using namespace std;
int minimum,min_past_num,num_town,m,start,goal;
struct Info{
Info(){
current_town = 0;
index = 0;
pre_town = 0;
// go_and_return = false;
}
int visited[102];
int current_town,index,costs[102],pre_town;
// bool go_and_return;
};
struct Data{
Data(int arg_to,int arg_cost){
to = arg_to;
cost = arg_cost;
}
int to,cost;
};
struct Node{
bool operator<(const struct Node &arg) const{ //sort??????????????????????????????????????????
return cost < arg.cost;
};
Node(int arg_town,int arg_cost){
town = arg_town;
cost = arg_cost;
}
int town,cost;
};
vector<Data> V[101];
void func(Info info){
int sum = 0,maximum = 0;
if(info.index == 1){
sum = info.costs[0];
}else if(info.index == 2){
sum =0;
}else{
sum = info.costs[0]+info.costs[1];
maximum = sum;
for(int i = 2; i < info.index;i++){
sum += info.costs[i];
maximum = max(maximum,info.costs[i]+info.costs[i-1]);
}
//rest = sum - info.costs[info.index-1];
sum = sum - maximum;
}
if(info.current_town == goal){
minimum = min(minimum,sum);
return;
}else{
if(info.index > 2 && sum >= minimum){
return;
}
}
for(int i = 0; i < V[info.current_town].size(); i++){
if(info.visited[V[info.current_town][i].to] == 0){
Info new_info;
for(int k = 1; k <= num_town; k++)new_info.visited[k] = info.visited[k];
new_info.visited[V[info.current_town][i].to]++;
new_info.current_town = V[info.current_town][i].to;
for(int k = 0; k < info.index; k++)new_info.costs[k] = info.costs[k];
new_info.costs[info.index] = V[info.current_town][i].cost;
new_info.pre_town = info.current_town;
new_info.index = info.index+1;
//new_info.go_and_return = info.go_and_return;
func(new_info);
}else if(info.visited[V[info.current_town][i].to] == 1 && info.pre_town == V[info.current_town][i].to){
Info new_info;
for(int k = 1; k <= num_town; k++)new_info.visited[k] = info.visited[k];
new_info.visited[V[info.current_town][i].to]++;
new_info.current_town = V[info.current_town][i].to;
for(int k = 0; k < info.index; k++)new_info.costs[k] = info.costs[k];
new_info.costs[info.index] = V[info.current_town][i].cost;
new_info.pre_town = info.current_town;
new_info.index = info.index+1;
//new_info.go_and_return = true;
func(new_info);
}
}
}
int main(){
int from,to,fee;
start = 1;
while(true){
scanf("%d %d",&num_town,&m);
if(num_town == 0 && m == 0)break;
goal = num_town;
minimum = 2000000000;
for(int i = 1; i <= num_town; i++)V[i].clear();
int costTable[num_town+1][num_town+1];
for(int i = 1; i <= num_town; i++){
for(int k = 1; k <= num_town;k++){
costTable[i][k] = NUM;
}
}
for(int i = 0; i < m; i++){
scanf("%d %d %d",&from,&to,&fee);
V[from].push_back(Data(to,fee));
V[to].push_back(Data(from,fee));
costTable[from][to] = fee;
costTable[to][from] = fee;
}
int past[num_town+1]; //???????????±????¨??????????????????????
for(int i = 1; i <= num_town; i++)past[i] = 1;
//????????????????????§??????????????????????????????????????????<??????????????????>
priority_queue<Node> Q;
int D[num_town+1];
bool visited[num_town+1];
for(int i = 1; i <= num_town; i++){
D[i] = NUM;
visited[i] = false;
}
visited[1] = true;
for(int i = 0; i < V[1].size(); i++){
D[V[1][i]] = costTable[1][V[1][i]];
}
int count = 1,current_min,current_min_index;
while(count < num_town){
current_min = NUM;
for(int i = 1; i <= num_town; i++){
if(D[i] < current_min && visited[i] == false){ //????????????????????????visited???true????????£???????????????<TE??????PQ?????????>
current_min = D[i];
current_min_index = i;
}
}
if(current_min == NUM)break;
visited[current_min_index] = true;
count++;
for(int i = 1; i <= num_town; i++){
if(costTable[current_min_index][i] != NUM && D[i] > D[current_min_index] + costTable[current_min_index][i]){
D[i] = D[current_min_index] + costTable[current_min_index][i];
past[i] = current_min_index;
}
}
}
int base_costs[num_town+1],base_index = 0,t;
t = goal;
while(true){
base_costs[base_index++] = costTable[t][past[t]];
t = past[t];
if(t == 1)break;
}
int meyasu = 0,meyasu_max = 0;
if(base_index == 1){
minimum = base_costs[0];
}else if(base_index == 2){
minimum = 0;
}else{
meyasu = base_costs[0] + base_costs[1];
meyasu_max = meyasu;
for(int i = 2; i < base_index; i++){
meyasu += base_costs[i];
meyasu_max = max(meyasu_max,base_costs[i] + base_costs[i-1]);
}
meyasu -= meyasu_max;
minimum = meyasu;
}
Info info;
for(int i = 1; i <= num_town;i++)info.visited[i] = 0;
info.current_town = start;
info.visited[start]++;
func(info);
printf("%d\n",minimum);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:157:18: error: no match for 'operator[]' (operand types are 'int [(num_town + 1)]' and '__gnu_cxx::__alloc_traits<std::allocator<Data>, Data>::value_type' {aka 'Data'})
157 | D[V[1][i]] = costTable[1][V[1][i]];
| ^
a.cc:157:42: error: no match for 'operator[]' (operand types are 'int [(num_town + 1)]' and '__gnu_cxx::__alloc_traits<std::allocator<Data>, Data>::value_type' {aka 'Data'})
157 | D[V[1][i]] = costTable[1][V[1][i]];
| ^
|
s808191126 | p00244 | C++ | #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a,b,c,d[101][101];
bool t[101][101];
main(){
cin.tie(0);
sync_with_stdio(false);
while(cin>>n>>m,n){
int ans=1e9;
r(i,n)r(j,n)d[i][j]=i==j?0:1e8;
memset(t,0,sizeof(t));
r(i,m){
cin>>a>>b>>c;a--;b--;
d[a][b]=d[b][a]=c;
t[a][b]=t[b][a]=1;
}
r(o,n)r(i,n)r(j,n)d[i][j]=min(d[i][j],d[i][o]+d[o][j]);
r(o,n)r(i,n)r(j,n)if(t[i][o]&&t[o][j])ans=min(ans,d[0][i]+d[j][n-1]);
cout<<ans<<endl;
}
} | a.cc:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main(){
| ^~~~
a.cc: In function 'int main()':
a.cc:8:3: error: 'sync_with_stdio' was not declared in this scope
8 | sync_with_stdio(false);
| ^~~~~~~~~~~~~~~
|
s789552146 | p00244 | C++ | #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a,b,c,d[101][101];
bool t[101][101];
main(){
cin.tie(0);
sync_with_stdio(false);
while(cin>>n>>m,n){
int ans=1e9;
r(i,n)r(j,n)d[i][j]=i==j?0:1e8;
memset(t,0,sizeof(t));
r(i,m){
cin>>a>>b>>c;a--;b--;
d[a][b]=d[b][a]=c;
t[a][b]=t[b][a]=1;
}
r(o,n)r(i,n)r(j,n)d[i][j]=min(d[i][j],d[i][o]+d[o][j]);
r(o,n)r(i,n)r(j,n)if(t[i][o]&&t[o][j])ans=min(ans,d[0][i]+d[j][n-1]);
cout<<ans<<endl;
}
} | a.cc:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main(){
| ^~~~
a.cc: In function 'int main()':
a.cc:8:3: error: 'sync_with_stdio' was not declared in this scope
8 | sync_with_stdio(false);
| ^~~~~~~~~~~~~~~
|
s171258206 | p00244 | C++ | #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a,b,c,d[101][101];
bool t[101][101];
cin.tie(0);
sync_with_stdio(false);
main(){
while(cin>>n>>m,n){
int ans=1e9;
r(i,n)r(j,n)d[i][j]=i==j?0:1e8;
memset(t,0,sizeof(t));
r(i,m){
cin>>a>>b>>c;a--;b--;
d[a][b]=d[b][a]=c;
t[a][b]=t[b][a]=1;
}
r(o,n)r(i,n)r(j,n)d[i][j]=min(d[i][j],d[i][o]+d[o][j]);
r(o,n)r(i,n)r(j,n)if(t[i][o]&&t[o][j])ans=min(ans,d[0][i]+d[j][n-1]);
cout<<ans<<endl;
}
} | a.cc:6:1: error: 'cin' does not name a type
6 | cin.tie(0);
| ^~~
a.cc:7:16: error: expected constructor, destructor, or type conversion before '(' token
7 | sync_with_stdio(false);
| ^
a.cc:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main(){
| ^~~~
|
s102274546 | p00244 | C++ | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
int to, cost;
edge() {}
edge(int to, int cost) : to(to), cost(cost) {}
};
const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
vector<edge> graph[100];
int dp[100][2];
int N, M;
int dijkstra()
{
priority_queue<T, vector<T>, greater<T>> que;
rep(i, 100) rep(j, 2) dp[i][j] = iINF;
dp[0][0] = 0;
que.push(T{0, 0, 0});
while (!que.empty())
{
int now, dist, used;
tie(dist, now, used) = que.top();
que.pop();
if (dp[now][used] < dist)
continue;
for (auto e : graph[now])
{
if (dp[now][used] + e.cost >= dp[e.to][used])
continue;
dp[e.to][used] = dp[now][used] + e.cost;
que.push(T{dp[e.to][used], e.to, used});
if (used)
continue;
int next = e.to;
for (auto ed : graph[next])
{
if (dp[now][0] >= dp[ed.to][1])
continue;
dp[ed.to][1] = dp[now][0];
que.push(T{dp[ed.to][1], ed.to, 1});
}
}
}
return min(dp[N - 1][0], dp[N - 1][1]);
}
int main()
{
while (cin >> N >> M && N)
{
rep(i, 100) graph[i].clear();
rep(i, M)
{
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
graph[a].push_back({b, c});
graph[b].push_back({a, c});
}
cout << dijkstra() << endl;
}
return 0;
}
| a.cc:13:5: error: ISO C++ forbids declaration of 'edge' with no type [-fpermissive]
13 | edge() {}
| ^~~~
a.cc:14:5: error: ISO C++ forbids declaration of 'edge' with no type [-fpermissive]
14 | edge(int to, int cost) : to(to), cost(cost) {}
| ^~~~
a.cc: In member function 'int<unnamed struct>::edge()':
a.cc:13:13: warning: no return statement in function returning non-void [-Wreturn-type]
13 | edge() {}
| ^
a.cc: In member function 'int<unnamed struct>::edge(int, int)':
a.cc:14:30: error: only constructors take member initializers
14 | edge(int to, int cost) : to(to), cost(cost) {}
| ^~
a.cc:14:50: warning: no return statement in function returning non-void [-Wreturn-type]
14 | edge(int to, int cost) : to(to), cost(cost) {}
| ^
|
s825494746 | p00244 | C++ | #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(void){
int graph[101][101],cpy[101][101],n,m,a,b,c;
while(cin >> n >> m,n|m){
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
graph[i][j]=cpy[i][j]=10000000;
}
graph[i][i]=0;
}
for(int i=0;i<m;i++){
cin >> a >> b >> c;
graph[a][b]=graph[b][a]=cpy[a][b]=cpy[b][a]=c;
}
for(int k=0;k<=n;k++)
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
graph[i][j]=graph[j][i]=min(graph[i][j],graph[i][k]+graph[k][j]);
int ans=INT_MAX;
for(int k=0;k<=n;k++)
for(int i=0;i<=n;i++)
if(cpy[i][k]<10000000)
for(int j=0;j<=n;j++)
if(cpy[k][j]<10000000)
ans=min(ans,graph[1][i]+graph[j][n]);
cout << ans << endl;
}
} | a.cc: In function 'int main()':
a.cc:29:13: error: 'INT_MAX' was not declared in this scope
29 | int ans=INT_MAX;
| ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
3 | #include<algorithm>
+++ |+#include <climits>
4 |
|
s024991504 | p00244 | C++ | #include <iostream>
#include <vector>
using namespace std;
#define INF (1 << 10)
typedef pair<int, int> P;
int main() {
int n, m;
while (cin >> n >> m, n || m) {
vector< vector<int> > cost(n, vector<int>(n, INF));
vector< vector<int> > connect(n, vector<int>(n, 0));
for (int i = 0; i < n; ++i)
cost[i][i] = 0;
for (int i = 0; i < m; ++i) {
int a, b, c; cin >> a >> b >> c;
--a, --b;
cost[a][b] = cost[b][a] = c;
connect[a][b] = 1;
}
vector<P> koho;
for (int i = 0; i < n; ++i)
for (int j = i+1; j < n; ++j)
for (int k = 0; k < n; ++k)
if (i != j && connect[i][k] && connect[k][j])
koho.push_back( P(i, j) );
koho.erase( unique( koho.begin(), koho.end() ), koho.end() );
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k < n; ++k)
if (cost[i][k] + cost[k][j] < cost[i][j])
cost[i][j] = cost[i][k] + cost[k][j];
int ans = cost[0][n-1];
for (int x = 0; x != koho.size(); ++x) {
vector< vector<int> > c = cost;
c[koho[x].first][koho[x].second] = c[koho[x].second][koho[x].first] = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k < n; ++k)
if (c[i][k] + c[k][j] < c[i][j])
c[i][j] = c[i][k] + c[k][j];
if (c[0][n-1] < ans) ans = c[0][n-1];
}
cout << ans << endl;
}
} | a.cc: In function 'int main()':
a.cc:33:29: error: 'unique' was not declared in this scope
33 | koho.erase( unique( koho.begin(), koho.end() ), koho.end() );
| ^~~~~~
|
s698574614 | p00244 | C++ | #include <iostream>
#include <vector>
using namespace std;
#define INF (1 << 10)
typedef pair<int, int> P;
int main() {
int n, m;
while (cin >> n >> m, n || m) {
vector< vector<int> > cost(n, vector<int>(n, INF));
vector< vector<int> > connect(n, vector<int>(n, 0));
for (int i = 0; i < n; ++i)
cost[i][i] = 0;
for (int i = 0; i < m; ++i) {
int a, b, c; cin >> a >> b >> c;
--a, --b;
cost[a][b] = cost[b][a] = c;
connect[a][b] = 1;
}
vector<P> koho;
for (int i = 0; i < n; ++i)
for (int j = i+1; j < n; ++j)
for (int k = 0; k < n; ++k)
if (i != j && connect[i][k] && connect[k][j])
koho.push_back( P(i, j) );
koho.erase( unique( koho.begin(), koho.end() ), koho.end() );
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k < n; ++k)
if (cost[i][k] + cost[k][j] < cost[i][j])
cost[i][j] = cost[i][k] + cost[k][j];
int ans = cost[0][n-1];
for (int x = 0; x != koho.size(); ++x) {
vector< vector<int> > c = cost;
c[koho[x].first][koho[x].second] = c[koho[x].second][koho[x].first] = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k < n; ++k)
if (c[i][k] + c[k][j] < c[i][j])
c[i][j] = c[i][k] + c[k][j];
if (c[0][n-1] < ans) ans = c[0][n-1];
}
cout << ans << endl;
}
} | a.cc: In function 'int main()':
a.cc:33:29: error: 'unique' was not declared in this scope
33 | koho.erase( unique( koho.begin(), koho.end() ), koho.end() );
| ^~~~~~
|
s393826916 | p00244 | C++ | #include<iostream>
#include<algorithm>
#define INF 1<<20
using namespace std;
int main(){
int n,m,s,e,c;
while(true){
cin >> n >> m;
if(n+m == 0)break;
int lst[n+1][n+1];
int Graph[n+1][n+1];
for(int i=0;i<n+1;i++)for(int j=0;j<n+1;j++){
lst[j][i] = i==j?0:INF;
Graph[i][j] = INF;
}
for(int i=0;i<m;i++){
cin >> s >> e >> c;
Graph[s][e] = Graph[e][s] = lst[s][e] = lst[e][s] = c;
}
for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)lst[i][j] = min(lst[i][j],lst[i][k]+lst[k][j]);
int cost = lst[1][n];
for(int k=1;k<=n;k++){
if(Graph[k][i] == INF)continue;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(Graph[k][i] != INF && Graph[k][j] != INF){
cost = min(cost,lst[1][i]+lst[j][n]);
}
}
}
}
cout << cost << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:26:13: error: 'i' was not declared in this scope
26 | if(Graph[k][i] == INF)continue;
| ^
|
s458334971 | p00245 | C++ | #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
struct Cell{
Cell(int arg_row,int arg_col){
row = arg_row;
col = arg_col;
}
bool operator<(const struct Cell &arg) const{
if(row != arg.row){
return row < arg.row;
}else{
return col < arg.col;
}
};
int row,col;
};
struct Info{
int discount,start,end;
};
struct Data{
Data(int arg_row,int arg_col,int arg_total_dist){
row = arg_row;
col = arg_col;
total_dist = arg_total_dist;
}
int row,col,total_dist;
};
struct SALE{
SALE(){
state = time = row = col = sum_discount = 0;
}
SALE(int arg_state,int arg_time,int arg_row,int arg_col,int arg_sum_discount){
state = arg_state;
time = arg_time;
row = arg_row;
col = arg_col;
sum_discount = arg_sum_discount;
}
int state,time,row,col,sum_discount;
};
int W,H;
int POW[11];
int dp[1024][20][20];
Info info[10];
bool is_sale[10];
int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
char base_map[20][21];
bool rangeCheck(int row,int col){
if(row >= 0 && row <= H-1 && col >= 0 && col <= W-1)return true;
else{
return false;
}
}
void func(){
char buf[2];
int start_row,start_col;
for(int row = 0; row < H; row++){
for(int col = 0; col < W; col++){
scanf("%s",buf);
base_map[row][col] = buf[0];
if(buf[0] == 'P'){
base_map[row][col] = '.';
start_row = row;
start_col = col;
}
}
}
int N;
scanf("%d",&N);
int g,d,s,e;
for(int i = 0; i < 10; i++)is_sale[i] = false;
for(int loop = 0; loop < N; loop++){
scanf("%d %d %d %d",&g,&d,&s,&e);
info[g].discount = d;
info[g].start = s;
info[g].end = e;
is_sale[g] = true;
}
int limit = POW[10];
for(int state = 0; state < limit; state++){
for(int row = 0; row < H; row++){
for(int col = 0; col < W; col++){
//dp[state][row][col] = BIG_NUM; //????????????????????????
dp[state][row][col] = -1;
}
}
}
queue<SALE> Q;
dp[0][start_row][start_col] = 0;
SALE first;
first.row = start_row;
first.col = start_col;
first.state = 0;
first.sum_discount = 0;
first.time = 0;
Q.push(first);
int max_value = 0;
while(!Q.empty()){
//printf("row:%d col:%d time:%d sum:%d state:%d\n",Q.front().row,Q.front().col,Q.front().time,Q.front().sum_discount,Q.front().state);
max_value = max(max_value,Q.front().sum_discount);
for(int i = 0; i < 4; i++){
int adj_row = Q.front().row + diff_row[i];
int adj_col = Q.front().col + diff_col[i];
if(rangeCheck(adj_row,adj_col) == false)continue;
if(base_map[adj_row][adj_col] == '.'){ //???????????´???
if(dp[Q.front().state][adj_row][adj_col] < Q.front().sum_discount){
dp[Q.front().state][adj_row][adj_col] = Q.front().sum_discount;
SALE next_sale;
next_sale.row = adj_row;
next_sale.col = adj_col;
next_sale.state = Q.front().state;
next_sale.sum_discount = Q.front().sum_discount;
next_sale.time = Q.front().time+1;
//printf("?????? row:%d col:%d?????????%d state:%d??§????§?\n",adj_row,adj_col,Q.front().time+1,Q.front().state);
Q.push(next_sale);
}
}else if(base_map[adj_row][adj_col] >= '0' && base_map[adj_row][adj_col] <= '9'){
int adj_item = base_map[adj_row][adj_col]-'0';
if(Q.front().state & (1 << adj_item))continue;
if(is_sale[adj_item] == false)continue;
int next_state = Q.front().state + POW[adj_item];
if(Q.front().time >= info[adj_item].start && Q.front().time < info[adj_item].end){ //??????????§??????????????????§?????????????????????
if(dp[next_state][Q.front().row][Q.front().col] < Q.front().sum_discount+info[adj_item].discount){
dp[next_state][Q.front().row][Q.front().col] = Q.front().sum_discount+info[adj_item].discount;
SALE next_sale;
next_sale.row = Q.front().row;
next_sale.col = Q.front().col;
next_sale.state = next_state;
next_sale.sum_discount = Q.front().sum_discount+info[adj_item].discount;
next_sale.time = Q.front().time;
//printf("?????? row:%d col:%d?????????%d state:%d??§????§?\n",adj_row,adj_col,Q.front().time+1,Q.front().state);
Q.push(next_sale);
}
}else if(Q.front().time < info[adj_item].start){
/*if(dp[next_state][Q.front().row][Q.front().col] < Q.front().sum_discount+info[adj_item].discount){
dp[next_state][Q.front().row][Q.front().col] = Q.front().sum_discount+info[adj_item].discount;*/
SALE next_sale;
next_sale.row = Q.front().row;
next_sale.col = Q.front().col;
next_sale.state = Q.front().state;
next_sale.sum_discount = Q.front().sum_discount;
next_sale.time = info[adj_item].start;
//printf("?????\?????? row:%d col:%d?????????%d state:%d??§????§?\n",adj_row,adj_col,Q.front().time+1,Q.front().state);
Q.push(next_sale);
/*}
}*/
}
}
Q.pop();
}
printf("%d\n",max_value);
}
int main(){
for(int i = 0; i <= 10; i++)POW[i] = pow(2,i);
while(true){
scanf("%d %d",&W,&H);
if(W == 0 && H == 0)break;
func();
}
return 0;
} | a.cc: In function 'void func()':
a.cc:224:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
224 | int main(){
| ^~
a.cc:224:9: note: remove parentheses to default-initialize a variable
224 | int main(){
| ^~
| --
a.cc:224:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:224:11: error: a function-definition is not allowed here before '{' token
224 | int main(){
| ^
a.cc:236:2: error: expected '}' at end of input
236 | }
| ^
a.cc:82:12: note: to match this '{'
82 | void func(){
| ^
|
s402137212 | p00245 | C++ | #include <iostream>
#include <map>
#include <vector>
using namespace std;
int dx[] = {0, 0, 0, +1, -1};
int dy[] = {0, +1, -1, 0, 0};
struct Type
{
int value, start, end;
Type(int value = 0, int start = 0, int end = 0) : value(value), start(start), end(end) {}
};
int H, W, N;
Type types[8];
map<char, int> table;
char board[20][20];
int memo[20][20][101][1 << 8];
int rec(int x, int y, int t, int used)
{
if(t == 101) return 0;
if(used + 1 == 1 << N) return 0;
if(memo[x][y][t][used] != -1) return memo[x][y][t][used];
int res = 0;
for(int i = 0; i < 5; i++)
{
int nx = x + dx[i], ny = y + dy[i];
if(0 <= nx && nx < W && 0 <= ny && ny <H)
{
char data = board[nx][ny];
if('0' <= data && data <= '9')
{
int idx = table[data];
int s = types[idx].start;
int e = types[idx].end;
if(s <= t && t < e && (used & 1 << idx) == 0)
res = max(res, rec(x, y, t, used | 1 << idx) + types[idx].value);
}
else res = max(res, rec(nx, ny, t + 1, used));
}
}
return memo[x][y][t][used] = res;
}
int solve()
{
memset(memo, -1, sizeof memo);
int X, Y;
for(int y = 0; y < H; y++)
{
for(int x = 0; x < W; x++)
{
char k;
cin >> k;
board[x][y] = k;
if(board[x][y] == 'P')
{
X = x;
Y = y;
}
}
}
cin >> N;
for(int i = 0; i < N; i++)
{
char c;
cin >> c >> types[i].value >> types[i].start >> types[i].end;
table[c] = i;
}
return rec(X, Y, 0, 0);
}
int main()
{
for(; cin >> W >> H && W;)
cout << solve() << endl;
} | a.cc: In function 'int solve()':
a.cc:54:9: error: 'memset' was not declared in this scope
54 | memset(memo, -1, sizeof memo);
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <vector>
+++ |+#include <cstring>
4 | using namespace std;
|
s221020545 | p00245 | C++ | #include <iostream>
#include <map>
#include <vector>
using namespace std;
int dx[] = {0, 0, 0, +1, -1};
int dy[] = {0, +1, -1, 0, 0};
struct Type
{
int value, start, end;
Type(int value = 0, int start = 0, int end = 0) : value(value), start(start), end(end) {}
};
int H, W, N;
Type types[8];
map<char, int> table;
char board[20][20];
int memo[20][20][101][1 << 8];
int rec(int x, int y, int t, int used)
{
if(t == 101) return 0;
if(used + 1 == 1 << N) return 0;
if(memo[x][y][t][used] != -1) return memo[x][y][t][used];
int res = 0;
for(int i = 0; i < 5; i++)
{
int nx = x + dx[i], ny = y + dy[i];
if(0 <= nx && nx < W && 0 <= ny && ny <H)
{
char data = board[nx][ny];
if('0' <= data && data <= '9')
{
int idx = table[data];
int s = types[idx].start;
int e = types[idx].end;
if(s <= t && t < e && (used & 1 << idx) == 0)
res = max(res, rec(x, y, t, used | 1 << idx) + types[idx].value);
}
else res = max(res, rec(nx, ny, t + 1, used));
}
}
return memo[x][y][t][used] = res;
}
int solve()
{
memset(memo, -1, sizeof memo);
int X, Y;
for(int y = 0; y < H; y++)
{
for(int x = 0; x < W; x++)
{
char k;
cin >> k;
board[x][y] = k;
if(board[x][y] == 'P')
{
X = x;
Y = y;
}
}
}
cin >> N;
for(int i = 0; i < N; i++)
{
char c;
cin >> c >> types[i].value >> types[i].start >> types[i].end;
table[c] = i;
}
return rec(X, Y, 0, 0);
}
int main()
{
for(; cin >> W >> H && W;)
cout << solve() << endl;
} | a.cc: In function 'int solve()':
a.cc:54:9: error: 'memset' was not declared in this scope
54 | memset(memo, -1, sizeof memo);
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <vector>
+++ |+#include <cstring>
4 | using namespace std;
|
s604450913 | p00245 | C++ | #include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
struct node{
int x,y,bit,t;
node(int x,int y,int bit,int t) : x(x) , y(y) , bit(bit) , t(t) {}
};
int x,y;
int sx,sy;
int n;
char c[22][22];
int num[10],d[10],s[10],e[10];
int value[1<<10];
int done[22][22][1<<10][102];
int dx[5]={0,0,1,-1,0},dy[5]={1,-1,0,0,0};
int main(void){
while(1){
scanf("%d%d",&x,&y);
if(x==0 && y==0)break;
queue<node> que;
for(int i=0;i<=21;i++){
for(int j=0;j<=21;j++){
c[i][j]='#';
}
}
for(int i=1;i<=y;i++){
for(int j=1;j<=x;j++){
cin >> c[j][i];
if(c[j][i]=='P'){
que.push(node(j,i,0,0));
c[j][i]='.';
}
}
}
scanf("%d",&n);
for(int i=0;i<n;i++){
int a;
scanf("%d",&a);
scanf("%d%d%d",&d[a],&s[a],&e[a]);
}
for(int i=0;i<(1<<n);i++){
for(int j=0;j<n;j++){
value[i]+=(i>>j&1)*d[j];
}
//cout << value[i] << " " << i << endl;
}
memset(done,0,sizeof(done));
int ans=0;
while(que.size()){
node q=que.front();que.pop();
if(q.t>100)continue;
if(c[q.x][q.y]!='.')continue;
for(int i=0;i<4;i++){
int tx=q.x+dx[i];
int ty=q.y+dy[i];
if(c[tx][ty]>='0' && c[tx][ty]<='9'){
int idx=c[tx][ty]-'0';
if(s[idx]<=q.t && q.t<e[idx])q.bit |= 1<<idx;
}
}
if(done[q.x][q.y][q.bit][q.t]++)continue;
ans=max(ans,value[q.bit]);
for(int i=0;i<5;i++){
que.push(node(q.x+dx[i],q.y+dy[i],q.bit,q.t+1));
}
}
cout << ans << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:51:17: error: 'memset' was not declared in this scope
51 | memset(done,0,sizeof(done));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include<queue>
+++ |+#include <cstring>
4 | using namespace std;
|
s492023533 | p00245 | C++ | #include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int INF = 1001001001;
const double EPS = 1e-10;
struct Data {
int y, x, t, mask;
Data(int y, int x, int t, int m) : y(y), x(x), t(t), mask(m) {}
};
struct Sale {
int d, s, e;
};
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
bool visited[20][20][100][1<<8];
int main()
{
int h, w;
while(scanf("%d%d", &w, &h), w){
char field[20][20];
rep(i, h) rep(j, w){
char c[4];
scanf("%s", c);
field[i][j] = c[0];
}
int n;
scanf("%d", &n);
int dict[10];
fill(dict, dict+10, -1);
Sale sale[8];
rep(i, n){
int g;
scanf("%d%d%d%d", &g, &sale[i].d, &sale[i].s, &sale[i].e);
dict[g] = i;
if(sale[i].s == 100){
assert(false);
for(;;);
}
}
rep(i, h) rep(j, w){
if(isdigit(field[i][j])){
int v = dict[field[i][j] - '0'];
if(v == -1)
field[i][j] = 'x';
else
field[i][j] = v + '0';
}
}
int mask[20][20];
rep(i, h) rep(j, w){
if(isdigit(field[i][j]) || field[i][j] == 'x')
mask[i][j] = -1;
else{
mask[i][j] = 0;
rep(k, 4){
int py = i + dy[k];
int px = j + dx[k];
if(py<0 || h<=py || px<0 || w<=px)
continue;
if(isdigit(field[py][px]))
mask[i][j] |= 1 << (field[py][px] - '0');
}
}
}
int money[1<<8];
rep(m, 1<<n){
money[m] = 0;
rep(i, n){
if((m>>i)&1)
money[m] += sale[i].d;
}
}
queue<Data> Q;
rep(i, h) rep(j, w){
if(field[i][j] == 'P'){
Q.push(Data(i, j, 0, 0));
goto next;
}
}
next:
int ans = 0;
while(!Q.empty()){
Data d = Q.front();
Q.pop();
rep(i, n){
if(((mask[d.y][d.x]>>i)&1) && sale[i].s<=d.t && d.t<sale[i].e)
d.mask |= 1 << i;
}
if(visited[d.y][d.x][d.t][d.mask])
continue;
visited[d.y][d.x][d.t][d.mask] = true;
ans = max(ans, money[d.mask]);
if(d.t == 99)
continue;
Q.push(Data(d.y, d.x, d.t+1, d.mask));
rep(k, 4){
int py = d.y + dy[k];
int px = d.x + dx[k];
if(py<0 || h<=py || px<0 || w<=px || mask[py][px]==-1)
continue;
Q.push(Data(py, px, d.t+1, d.mask));
}
}
printf("%d\n", ans);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:65:33: error: 'assert' was not declared in this scope
65 | assert(false);
| ^~~~~~
a.cc:15:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
14 | #include <stack>
+++ |+#include <cassert>
15 | #include <string>
|
s854611183 | p00246 | C++ | #include<iostream>
#include<vector>
#include<cmath>
#include<Windows.h>
using namespace std;
void part(int x, vector<int> &d, vector<vector<int> > &a, int pre)
{
if ( x == 0 ) {
a.push_back(d);
}
for (int i = pre; i >= 1; --i) {
if (x - i >= 0) {
d.push_back(i);
part(x - i, d, a, i);
d.pop_back();
}
}
}
const int NPAT = 41;
int res;
int parts[NPAT][9];
inline int ideal(int m[])
{
int ret = 0;
for (int i = 0; i < 9; ++i) {
ret += (i+1) * m[i];
}
return ret / 10;
}
bool solve(int m[], int pre, int step)
{
if ( res < step ) {
res = step;
}
if ( step + ideal(m) <= res ) {
return false;
}
for (int i = pre; i < NPAT; ++i) {
bool packable = true;
for (int j = 0; j < 9; ++j) {
if (m[j] < parts[ i ][ j ]) {
packable = false;
}
}
if ( packable ) {
// Translate
for (int j = 0; j < 9; ++j) {
m[j] -= parts[ i ][ j ];
}
// solve(m, i, step + 1);
if (solve(m, i, step + 1)) return true;
// Rollback
for ( int j = 0; j < 9; ++j ) {
m[j] += parts[ i ][ j ];
}
}
}
// cout << (res) << endl;
return true;
}
int main(void)
{
vector<int> d;
vector< vector<int> > s;
part(10, d, s, 9);
for (int sz = 2; sz < 22; ++sz){
for (int i = 0; i < s.size(); ++i){
if (s[i].size() == sz){
for (int j = 0; j < s[i].size(); ++j){
parts[i][s[i][j] - 1]++;
}
}
}
}
while ( true ) {
int n;
int m[9] = { 0, };
cin >> n;
if (n == 0) {
break;
}
for (int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
m[tmp - 1]++;
}
res = 0;
solve(m, 0, 0);
cout << res << endl;
}
return 0;
} | a.cc:4:9: fatal error: Windows.h: No such file or directory
4 | #include<Windows.h>
| ^~~~~~~~~~~
compilation terminated.
|
s221259489 | p00246 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> pr;
typedef pair<pr , pr > ppr;
typedef array<int,5> arafi;
int num[5]={},numTimes[5]={},numbers;
vector<array<int,5> > p;
void search(int times,int gets[5]){
if(times==numbers){
int sum=0;
for(int i=0;i<numbers;i++)
sum+=num[i]*gets[i];
if(sum==10){
arafi a={gets[0],gets[1],gets[2],gets[3],gets[4]};
p.push_back(a);
}
}
else{
for(int i=0;i<=numTimes[times] && i<=10 ;i++){
gets[times]=i;
search(times+1,gets);
}
}
}
int findAns(int x,int times[]){
if (x==p.size())
return 0;
int maxim=0,ans=1;
arafi ar=p[x];
for(int i=0;i<numbers;i++){
if(ar[i]>times[i])
ans=0;
times[i]-=ar[i];
}
if(ans)
maxim=max(maxim,1+findAns(x,times));
for(int i=0;i<numbers;i++)
times[i]+=ar[i];
maxim=max(maxim,findAns(x+1,times));
return maxim;
}
int solved(vector<pr> v){
int ans=0;
for(int i=0;i<v.size();i++){
num[i]=v[i].first;
numTimes[i]=v[i].second;
}
numbers=v.size();
int gets[5]={};
search(0,gets);
return findAns(0,numTimes);
}
int main() {
// your code goes here
int n,tmp;
while(cin >> n && n!=0){
p.clear();
numbers=0;
vector<pr > v;
int nums[10]={},sum=0;
for(int i=0;i<n;i++){
cin >> tmp;
nums[tmp]++;
}
for(int i=1;i<=4;i++)
if(nums[i] && nums[10-i]){
int manju=min(nums[i],nums[10-i]);
sum+=manju;
nums[i]-=manju;
nums[10-i]-=manju;
}
sum+=nums[5]/2;
nums[5]%=2;
for(int i=1;i<=8;i++)
if(nums[i])
v.push_back(pr(i,nums[i]));
cout << sum+solved(v) << endl;
}
return 0;
} | a.cc: In function 'void search(int, int*)':
a.cc:18:31: error: variable 'arafi a' has initializer but incomplete type
18 | arafi a={gets[0],gets[1],gets[2],gets[3],gets[4]};
| ^
a.cc: In function 'int findAns(int, int*)':
a.cc:33:15: error: variable 'arafi ar' has initializer but incomplete type
33 | arafi ar=p[x];
| ^~
In file included from /usr/include/c++/14/vector:66,
from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]':
/usr/include/c++/14/bits/stl_vector.h:531:7: required from here
531 | vector() = default;
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:369:49: error: invalid use of incomplete type 'struct std::array<int, 5>'
369 | _M_impl._M_end_of_storage - _M_impl._M_start);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
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_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
99 | struct array;
| ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; size_type = long unsigned int]':
a.cc:30:15: required from here
30 | if (x==p.size())
| ~~~~~~^~
/usr/include/c++/14/bits/stl_vector.h:993:50: error: invalid use of incomplete type 'struct std::array<int, 5>'
993 | { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
99 | struct array;
| ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; reference = std::array<int, 5>&; size_type = long unsigned int]':
a.cc:33:14: required from here
33 | arafi ar=p[x];
| ^
/usr/include/c++/14/bits/stl_vector.h:1131:41: error: invalid use of incomplete type 'struct std::array<int, 5>'
1131 | return *(this->_M_impl._M_start + __n);
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
99 | struct array;
| ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'void std::vector<_Tp, _Alloc>::_M_erase_at_end(pointer) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; pointer = std::array<int, 5>*]':
/usr/include/c++/14/bits/stl_vector.h:1608:9: required from 'void std::vector<_Tp, _Alloc>::clear() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]'
1608 | { _M_erase_at_end(this->_M_impl._M_start); }
| ^~~~~~~~~~~~~~~
a.cc:61:10: required from here
61 | p.clear();
| ~~~~~~~^~
/usr/include/c++/14/bits/stl_vector.h:1945:53: error: invalid use of incomplete type 'struct std::array<int, 5>'
1945 | if (size_type __n = this->_M_impl._M_finish - __pos)
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
99 | struct array;
| ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
from /usr/include/c++/14/bits/allocator.h:46,
from /usr/include/c++/14/string:43:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = std::array<int, 5>; size_type = long unsigned int]':
/usr/include/c++/14/bits/alloc_traits.h:550:23: required from 'static void std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = std::array<int, 5>; allocator_type = std::allocator<std::array<int, 5> >; pointer = std::array<int, 5>*; size_type = long unsigned int]'
550 | { __a.deallocate(__p, __n); }
| ~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:389:19: required from 'void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(pointer, std::size_t) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; pointer = std::array<int, 5>*; std::size_t = long unsigned int]'
389 | _Tr::deallocate(_M_impl, __p, __n);
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:368:2: required from 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]'
368 | _M_deallocate(_M_impl._M_start,
| ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:531:7: required from here
531 | vector() = default;
| ^~~~~~
/usr/include/c++/14/bits/new_allocator.h:165:13: error: invalid application of '__alignof__' to incomplete type 'std::array<int, 5>'
165 | if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:167:38: error: invalid application of 'sizeof' to incomplete type 'std::array<int, 5>'
167 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n),
| ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:168:55: error: invalid application of '__alignof__' to incomplete type 'std::array<int, 5>'
168 | std::align_val_t(alignof(_Tp)));
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:172:34: error: invalid application of 'sizeof' to incomplete type 'std::array<int, 5>'
172 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
| ^~~~~~~~~~~~~~~~~~~~~~
|
s434837071 | p00246 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> pr;
typedef pair<pr , pr > ppr;
typedef array<int,5> arafi;
int num[5]={},numTimes[5]={},numbers;
vector<array<int,5> > p;
void search(int times,int gets[5]){
if(times==numbers){
int sum=0;
for(int i=0;i<numbers;i++)
sum+=num[i]*gets[i];
if(sum==10){
arafi a={gets[0],gets[1],gets[2],gets[3],gets[4]};
p.push_back(a);
}
}
else{
for(int i=0;i<=numTimes[times] && i<=10 ;i++){
gets[times]=i;
search(times+1,gets);
}
}
}
int findAns(int x,int times[]){
if (x==p.size())
return 0;
int maxim=0,ans=1;
arafi ar=p[x];
for(int i=0;i<numbers;i++){
if(ar[i]>times[i])
ans=0;
times[i]-=ar[i];
}
if(ans)
maxim=max(maxim,1+findAns(x,times));
for(int i=0;i<numbers;i++)
times[i]+=ar[i];
maxim=max(maxim,findAns(x+1,times));
return maxim;
}
int solved(vector<pr> v){
int ans=0;
for(int i=0;i<v.size();i++){
num[i]=v[i].first;
numTimes[i]=v[i].second;
}
numbers=v.size();
int gets[5]={};
search(0,gets);
return findAns(0,numTimes);
}
int main() {
// your code goes here
int n,tmp;
while(cin >> n && n!=0){
p.clear();
numbers=0;
vector<pr > v;
int nums[10]={},sum=0;
for(int i=0;i<n;i++){
cin >> tmp;
nums[tmp]++;
}
for(int i=1;i<=4;i++)
if(nums[i] && nums[10-i]){
int manju=min(nums[i],nums[10-i]);
sum+=manju;
nums[i]-=manju;
nums[10-i]-=manju;
}
sum+=nums[5]/2;
nums[5]%=2;
for(int i=1;i<=8;i++)
if(nums[i])
v.push_back(pr(i,nums[i]));
cout << sum+solved(v) << endl;
}
return 0;
} | a.cc: In function 'void search(int, int*)':
a.cc:18:31: error: variable 'arafi a' has initializer but incomplete type
18 | arafi a={gets[0],gets[1],gets[2],gets[3],gets[4]};
| ^
a.cc: In function 'int findAns(int, int*)':
a.cc:33:15: error: variable 'arafi ar' has initializer but incomplete type
33 | arafi ar=p[x];
| ^~
In file included from /usr/include/c++/14/vector:66,
from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]':
/usr/include/c++/14/bits/stl_vector.h:531:7: required from here
531 | vector() = default;
| ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:369:49: error: invalid use of incomplete type 'struct std::array<int, 5>'
369 | _M_impl._M_end_of_storage - _M_impl._M_start);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
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_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
99 | struct array;
| ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; size_type = long unsigned int]':
a.cc:30:15: required from here
30 | if (x==p.size())
| ~~~~~~^~
/usr/include/c++/14/bits/stl_vector.h:993:50: error: invalid use of incomplete type 'struct std::array<int, 5>'
993 | { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
99 | struct array;
| ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; reference = std::array<int, 5>&; size_type = long unsigned int]':
a.cc:33:14: required from here
33 | arafi ar=p[x];
| ^
/usr/include/c++/14/bits/stl_vector.h:1131:41: error: invalid use of incomplete type 'struct std::array<int, 5>'
1131 | return *(this->_M_impl._M_start + __n);
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
99 | struct array;
| ^~~~~
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'void std::vector<_Tp, _Alloc>::_M_erase_at_end(pointer) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; pointer = std::array<int, 5>*]':
/usr/include/c++/14/bits/stl_vector.h:1608:9: required from 'void std::vector<_Tp, _Alloc>::clear() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]'
1608 | { _M_erase_at_end(this->_M_impl._M_start); }
| ^~~~~~~~~~~~~~~
a.cc:61:10: required from here
61 | p.clear();
| ~~~~~~~^~
/usr/include/c++/14/bits/stl_vector.h:1945:53: error: invalid use of incomplete type 'struct std::array<int, 5>'
1945 | if (size_type __n = this->_M_impl._M_finish - __pos)
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_pair.h:99:12: note: declaration of 'struct std::array<int, 5>'
99 | struct array;
| ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
from /usr/include/c++/14/bits/allocator.h:46,
from /usr/include/c++/14/string:43:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::deallocate(_Tp*, size_type) [with _Tp = std::array<int, 5>; size_type = long unsigned int]':
/usr/include/c++/14/bits/alloc_traits.h:550:23: required from 'static void std::allocator_traits<std::allocator<_CharT> >::deallocate(allocator_type&, pointer, size_type) [with _Tp = std::array<int, 5>; allocator_type = std::allocator<std::array<int, 5> >; pointer = std::array<int, 5>*; size_type = long unsigned int]'
550 | { __a.deallocate(__p, __n); }
| ~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:389:19: required from 'void std::_Vector_base<_Tp, _Alloc>::_M_deallocate(pointer, std::size_t) [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >; pointer = std::array<int, 5>*; std::size_t = long unsigned int]'
389 | _Tr::deallocate(_M_impl, __p, __n);
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:368:2: required from 'std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::array<int, 5>; _Alloc = std::allocator<std::array<int, 5> >]'
368 | _M_deallocate(_M_impl._M_start,
| ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:531:7: required from here
531 | vector() = default;
| ^~~~~~
/usr/include/c++/14/bits/new_allocator.h:165:13: error: invalid application of '__alignof__' to incomplete type 'std::array<int, 5>'
165 | if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:167:38: error: invalid application of 'sizeof' to incomplete type 'std::array<int, 5>'
167 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n),
| ^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:168:55: error: invalid application of '__alignof__' to incomplete type 'std::array<int, 5>'
168 | std::align_val_t(alignof(_Tp)));
| ^~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:172:34: error: invalid application of 'sizeof' to incomplete type 'std::array<int, 5>'
172 | _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
| ^~~~~~~~~~~~~~~~~~~~~~
|
s591595472 | p00246 | C++ | #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <cstring>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;
const int INF = 1001001001;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
const int CANDICATE_N = 36;
// 最初の6個は5を含む
int a[CANDICATE_N] = {65808, 69633, 65569, 65794, 65555, 65541, 277, 52, 4116, 516, 1048580, 291, 4102, 4355, 16777219, 66, 4130, 530, 1048594, 38, 8194, 268435458, 305, 263, 4369, 16777233, 769, 1048833, 24, 80, 4144, 544, 1048608, 10, 8208, 4608};
int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
int N, manju[10];
int rest[4], rest_b, base[4];
char dp[33*33*33*33][CANDICATE_N];
// i: a_index, j: rest_index
inline int at(int i, int j){
return a[i] >> (4*(rest[j]-1)) & 0xf;
}
// i: rest_index
inline int at2(int i){
return manju[rest[i]];
}
// i: a_index, j: rest_index
inline int at3(int i, int j){return at2(j) - at(i, j);}
inline char& at4(int i, int j, int k, int l, int index){
// (i+base[0]*(j+base[1]*(k+base[2]*l)) < 1000000)
return dp[i+base[0]*(j+base[1]*(k+base[2]*l))][index];
}
inline int at5(int i, int j){
return a[i] >> (4*(j-1)) & 0xf;
}
inline bool can(int a, int b, int c, int d, int index){
FOR(i, 1, 9){
//printf("index=%d, i=%d (in can)\n", index, i);
if(i == 5){continue;}
if(!(rest_b >> i & 1) && at5(index, i) > 0){return false;}
}
if(at(index, 0) == 0 && at(index, 1) == 0 &&
at(index, 2) == 0 && at(index, 3) == 0){;return false;}
return a >= at(index, 0) &&
b >= at(index, 1) &&
c >= at(index, 2) &&
d >= at(index, 3);
}
char rec(int a, int b, int c, int d, int index, int depth){
// printf("%d, %d, %d, %d, %d, %d\n", a, b, c, d, index, a+b+c+d);
// printf("[%d][%d][%d][%d]: %d\n",
// i, j, k, l,
// i+j*(at2(0)+1)+k*(at2(0)+at2(1)+2)+l*(at2(0)+at2(1)+at2(2)+3));
if(index == CANDICATE_N){return 0;}
if(a == 0 && b == 0 && c == 0 && d == 0){return 0;}
if(at4(a, b, c, d, index) != -1){return at4(a, b, c, d, index);}
char res = rec(a, b, c, d, index+1);
if(can(a, b, c, d, index)){
res = std::max(res, static_cast<char>(rec(a-at(index, 0), b-at(index, 1), c-at(index, 2), d-at(index, 3), index)+1));
}
// printf("dp[%d][%d][%d][%d][%d] = %d\n", a, b, c, d, index, res);
return at4(a, b, c, d, index) = res;
}
int main(){
while(std::cin >> N, N){
memset(manju, 0, sizeof(manju));
REP(i, N){
int w;
std::cin >> w;
manju[w] += 1;
}
// FOR(i, 1, 10){printf("%d: %d\n", i, manju[i]);}
char r1 = 0;
FOR(i, 1, 5){
int mn = std::min(manju[i], manju[10-i]);
r1 += mn;
manju[i] -= mn; manju[10-i] -= mn;
}
r1 += manju[5] >> 1;
manju[5] &= 1;
{
int n = 0;
std::fill(rest, rest+4, 1);
rest_b = 0;
FOR(i, 1, 10){
if(i == 5 || i == 9){continue;}
if(manju[i] > 0){
rest[n] = i;
rest_b |= 1 << i;
n += 1;
}
}
std::sort(rest, rest+4);
REP(i, 4){
for(int p : prime){if(manju[rest[i]] < p){base[i] = p; break;}}
}
}
memset(dp, -1, sizeof(dp));
char r2 = rec(at2(0), at2(1), at2(2), at2(3), 6);
if(manju[5] == 1){
REP(i, 6){
if(can(at2(0), at2(1), at2(2), at2(3), i)){
r2 = std::max(r2, static_cast<char>(rec(at3(i, 0), at3(i, 1), at3(i, 2), at3(i, 3), 6) + 1));
}
}
}
std::cout << (r1+r2) << std::endl;
}
} | a.cc: In function 'char rec(int, int, int, int, int, int)':
a.cc:84:19: error: too few arguments to function 'char rec(int, int, int, int, int, int)'
84 | char res = rec(a, b, c, d, index+1);
| ~~~^~~~~~~~~~~~~~~~~~~~~
a.cc:75:6: note: declared here
75 | char rec(int a, int b, int c, int d, int index, int depth){
| ^~~
a.cc:86:50: error: too few arguments to function 'char rec(int, int, int, int, int, int)'
86 | res = std::max(res, static_cast<char>(rec(a-at(index, 0), b-at(index, 1), c-at(index, 2), d-at(index, 3), index)+1));
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:75:6: note: declared here
75 | char rec(int a, int b, int c, int d, int index, int depth){
| ^~~
a.cc: In function 'int main()':
a.cc:138:22: error: too few arguments to function 'char rec(int, int, int, int, int, int)'
138 | char r2 = rec(at2(0), at2(1), at2(2), at2(3), 6);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:75:6: note: declared here
75 | char rec(int a, int b, int c, int d, int index, int depth){
| ^~~
a.cc:142:60: error: too few arguments to function 'char rec(int, int, int, int, int, int)'
142 | r2 = std::max(r2, static_cast<char>(rec(at3(i, 0), at3(i, 1), at3(i, 2), at3(i, 3), 6) + 1));
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:75:6: note: declared here
75 | char rec(int a, int b, int c, int d, int index, int depth){
| ^~~
|
s521043806 | p00246 | C++ | #include <bits/stdc++.h>
typedef unsigned long long hash_t;
std::mt19937 RND;
std::uniform_int_distribution<hash_t> DST;
#define random() (DST(RND))
hash_t hash_table[10][101];
std::vector<std::vector<int>> T;
std::map<hash_t, int> dp;
void dfs(int i, int s, std::vector<int> &v)
{
if (s == 0){
T.emplace_back(v);
return;
}
if (i > 9) return;
if (i > s) return;
v[i]++;
dfs(i, s - i, v);
v[i]--;
dfs(i + 1, s, v);
}
inline hash_t getHash(const std::vector<int> &v)
{
hash_t res = 0;
for (int i = 0; i < 10; i++){
res ^= hash_table[i][v[i]];
}
return res;
}
int calc(std::vector<int> &v, int pos = 0)
{
if (pos == T.size()) return 0;
hash_t hash = getHash(v);
if (dp.count(hash)) return dp[hash];
int res = calc(v, pos + 1);
auto &table = T[pos];
int k = 99;
for (int i = 0; i < table.size(); i++){
if (table[i] == 0) continue;
k = std::min(k, v[i] / table[i]);
}
for (int i = 1; i <= k; i++){
for (int j = 0; j < table.size(); j++){
v[j] -= table[j];
}
res = std::max(res, k + calc(v, pos + 1));
}
for (int j = 0; j < table.size(); j++){
v[j] += table[j] * k;
}
return dp[hash] = res;
}
int main()
{
for (int i = 0; i < 10; i++){
for (int j = 0; j <= 100; j++){
hash_table[i][j] = random();
}
}
dfs(1, 10, std::vector<int>(10, 0));
int n;
while (std::cin >> n, n){
std::vector<int> v(10, 0);
for (int i = 0; i < n; i++){
int a;
std::cin >> a;
v[a]++;
}
printf("%d\n", calc(v));
dp.clear();
}
return 0;
} | a.cc: In function 'int main()':
a.cc:73:25: error: cannot bind non-const lvalue reference of type 'std::vector<int>&' to an rvalue of type 'std::vector<int>'
73 | dfs(1, 10, std::vector<int>(10, 0));
| ^~~~~~~~~~~~~~~~~~
a.cc:13:42: note: initializing argument 3 of 'void dfs(int, int, std::vector<int>&)'
13 | void dfs(int i, int s, std::vector<int> &v)
| ~~~~~~~~~~~~~~~~~~^
|
s988808814 | p00246 | C++ | using namespace std;
map<vector<int>, int> m;
vector<vector<int> > mp;
int getMax(vector<int> p, int sum)
{
int a;
if (m.find(p) != m.end()){
return (m[p]);
}
if (sum < 10){
return (m[p] = 0);
}
a = 0;
for (int i = 0; i < (int)mp.size(); i++){
vector<int> c = p;
bool flag;
flag = true;
for (int j = 1; j < (int)mp[i].size(); j++){
c[j] -= mp[i][j];
if (c[j] < 0){
flag = false;
break;
}
}
if (flag == true){
a = max(a, 1 + getMax(c, sum - 10));
}
}
return (m[p] = a);
}
void make(vector<int> t, int n, int lim)
{
if (lim == 0 || n == 10){
if (!lim){
mp.push_back(t);
m[t] = 1;
}
return;
}
for (int i = 0; i * n <= lim; i++){
vector<int> tn = t;
tn.push_back(i);
make(tn, n + 1, lim - i * n);
}
return;
}
int main(void)
{
int n;
int ans;
vector<int> num(10);
vector<int> t;
t.push_back(0);
make(t, 1, 10);
while (scanf("%d", &n) && n){
fill(num.begin(), num.end(), 0);
for (int i = 0; i < n; i++){
int t;
scanf("%d", &t);
num[t]++;
}
ans = 0;
for (int i = 1; i <= 4; i++){
int m = min(num[i], num[10 - i]);
ans += m;
num[i] -= m; num[10 - i] -= m;
}
ans += num[5] / 2; num[5] %= 2;
int s = 0;
for (int i = 1; i <= 9; i++){
s += i * num[i];
}
printf("%d\n", ans + getMax(num, s));
}
return (0);
} | a.cc:3:1: error: 'map' does not name a type
3 | map<vector<int>, int> m;
| ^~~
a.cc:4:1: error: 'vector' does not name a type
4 | vector<vector<int> > mp;
| ^~~~~~
a.cc:6:12: error: 'vector' was not declared in this scope
6 | int getMax(vector<int> p, int sum)
| ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
+++ |+#include <vector>
1 | using namespace std;
a.cc:6:19: error: expected primary-expression before 'int'
6 | int getMax(vector<int> p, int sum)
| ^~~
a.cc:6:27: error: expected primary-expression before 'int'
6 | int getMax(vector<int> p, int sum)
| ^~~
a.cc:6:34: error: expression list treated as compound expression in initializer [-fpermissive]
6 | int getMax(vector<int> p, int sum)
| ^
a.cc:40:6: error: variable or field 'make' declared void
40 | void make(vector<int> t, int n, int lim)
| ^~~~
a.cc:40:11: error: 'vector' was not declared in this scope
40 | void make(vector<int> t, int n, int lim)
| ^~~~~~
a.cc:40:11: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:40:18: error: expected primary-expression before 'int'
40 | void make(vector<int> t, int n, int lim)
| ^~~
a.cc:40:26: error: expected primary-expression before 'int'
40 | void make(vector<int> t, int n, int lim)
| ^~~
a.cc:40:33: error: expected primary-expression before 'int'
40 | void make(vector<int> t, int n, int lim)
| ^~~
a.cc: In function 'int main()':
a.cc:63:9: error: 'vector' was not declared in this scope
63 | vector<int> num(10);
| ^~~~~~
a.cc:63:9: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:63:16: error: expected primary-expression before 'int'
63 | vector<int> num(10);
| ^~~
a.cc:64:16: error: expected primary-expression before 'int'
64 | vector<int> t;
| ^~~
a.cc:66:9: error: 't' was not declared in this scope
66 | t.push_back(0);
| ^
a.cc:67:9: error: 'make' was not declared in this scope
67 | make(t, 1, 10);
| ^~~~
a.cc:69:16: error: 'scanf' was not declared in this scope
69 | while (scanf("%d", &n) && n){
| ^~~~~
a.cc:71:22: error: 'num' was not declared in this scope; did you mean 'enum'?
71 | fill(num.begin(), num.end(), 0);
| ^~~
| enum
a.cc:71:17: error: 'fill' was not declared in this scope
71 | fill(num.begin(), num.end(), 0);
| ^~~~
a.cc:82:33: error: 'min' was not declared in this scope; did you mean 'main'?
82 | int m = min(num[i], num[10 - i]);
| ^~~
| main
a.cc:93:44: error: 'getMax' cannot be used as a function
93 | printf("%d\n", ans + getMax(num, s));
| ~~~~~~^~~~~~~~
a.cc:93:17: error: 'printf' was not declared in this scope
93 | printf("%d\n", ans + getMax(num, s));
| ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
+++ |+#include <cstdio>
1 | using namespace std;
|
s492606304 | p00246 | C++ | #include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
vector<vector<int> > select;
void manju(vector<int>& a, int prev, int sum, const vector<int>& x)
{
if(sum > 10)
return;
if(sum == 10){
if(accumulate(a.begin(), a.end(), 0) > 2)
select.push_back(a);
return;
}
for(int i=prev; i<=9; ++i){
if(x[i] == 0)
continue;
++ a[i];
sum += i;
manju(a, i, sum, x);
sum -= i;
-- a[i];
}
}
vector<map<vector<int>, int> > memo;
int solve(const vector<int>& x, int k)
{
if(k >= select.size())
return 0;
if(memo[k].find(x) != memo[k].end())
return memo[k][x];
int ret = solve(x, k+1);
vector<int> y = x;
bool ok = true;
for(int i=1; i<=9; ++i){
y[i] -= select[k][i];
if(y[i] < 0)
ok = false;
}
if(ok)
ret = max(ret, solve(y, k) + 1);
return memo[k][x] = ret;
}
int main()
{
for(;;){
int n;
cin >> n;
if(n == 0)
return 0;
vector<int> x(10, 0);
for(int i=0; i<n; ++i){
int y;
cin >> y;
if(x[10-y] > 0)
-- x[10-y];
else
++ x[y];
}
select.clear();
vector<int> a(10, 0);
manju(a, 1, 0, x);
memo.assign(select.size(), map<vector<int>, int>());
cout << solve(x, 0) << endl;
}
} | a.cc:20:22: error: 'std::vector<std::vector<int> > select' redeclared as different kind of entity
20 | vector<vector<int> > select;
| ^~~~~~
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:179,
from /usr/include/stdlib.h:514,
from /usr/include/c++/14/cstdlib:79,
from /usr/include/c++/14/ext/string_conversions.h:43,
from /usr/include/c++/14/bits/basic_string.h:4154,
from /usr/include/c++/14/string:54,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:2:
/usr/include/x86_64-linux-gnu/sys/select.h:102:12: note: previous declaration 'int select(int, fd_set*, fd_set*, fd_set*, timeval*)'
102 | extern int select (int __nfds, fd_set *__restrict __readfds,
| ^~~~~~
a.cc: In function 'void manju(std::vector<int>&, int, int, const std::vector<int>&)':
a.cc:27:20: error: request for member 'push_back' in 'select', which is of non-class type 'int(int, fd_set*, fd_set*, fd_set*, timeval*)'
27 | select.push_back(a);
| ^~~~~~~~~
a.cc: In function 'int solve(const std::vector<int>&, int)':
a.cc:45:20: error: request for member 'size' in 'select', which is of non-class type 'int(int, fd_set*, fd_set*, fd_set*, timeval*)'
45 | if(k >= select.size())
| ^~~~
a.cc:56:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
56 | y[i] -= select[k][i];
| ^
a.cc:56:28: warning: pointer to a function used in arithmetic [-Wpointer-arith]
56 | y[i] -= select[k][i];
| ^
a.cc:56:14: error: invalid operands of types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'int (*)(int, fd_set*, fd_set*, fd_set*, timeval*)' to binary 'operator-'
56 | y[i] -= select[k][i];
a.cc:56:14: note: in evaluation of 'operator-=(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}, int (*)(int, struct fd_set*, struct fd_set*, struct fd_set*, struct timeval*))'
a.cc: In function 'int main()':
a.cc:84:16: error: request for member 'clear' in 'select', which is of non-class type 'int(int, fd_set*, fd_set*, fd_set*, timeval*)'
84 | select.clear();
| ^~~~~
a.cc:88:28: error: request for member 'size' in 'select', which is of non-class type 'int(int, fd_set*, fd_set*, fd_set*, timeval*)'
88 | memo.assign(select.size(), map<vector<int>, int>());
| ^~~~
|
s984971456 | p00246 | C++ | 5
4 9 1 3 8
10
8 5 3 6 2 1 4 5 4 5
9
5 7 3 8 2 9 6 4 1
100
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 4 4 4 4 4
3 3 3 3 3 4 4 4 4 4
5 5 5 5 5 6 6 6 6 6
7 7 7 7 7 8 8 8 8 8
9 9 9 9 9 9 9 9 9 9
0 | a.cc:1:1: error: expected unqualified-id before numeric constant
1 | 5
| ^
|
s939705245 | p00246 | C++ | #include <iostream>
using namespace std;
int N;
int manto[11];
bool dfs(int No, int sum)
{
int x = manto[10];
if(sum == 10){
return true;
}
else if(sum > 10)
return false;
for(int i = No; i > 0; i--){
if(manto[i] > 0){
manto[i]--;
if(!dfs(i,sum+i))
manto[i]++;
else{
if(No == 9)
manto[10]++;
return true;
}
}
}
return false;
}
int main()
{
while(cin >> N, N){
int a;
for(int i = 0; i <= 10; i++){
manto[i] = 0;
}
for(int i = 0; i < N; i++){
cin >> a;
manto[a]++;
}
for(int i = 0; i < 9; i++){
if(i == 5){
if(manto[i] >= 2){
while(manto[i] >= 2){
manto[i] -= 2;
manto[10]++;
}
}
}
else if(manto[i] > 0 && manto[10-i] > 0){
while(manto[i] > 0 && manto[10-i] > 0){
manto[i]--;
manto[10-i]--;
manto[10]++;
}
}
}
while(dfs(9,0));
printf("%d\n", manto[10])
}
return 0;
} | a.cc: In function 'int main()':
a.cc:69:42: error: expected ';' before '}' token
69 | printf("%d\n", manto[10])
| ^
| ;
70 | }
| ~
|
s855763921 | p00246 | C++ | #include <iostream>
#include <cstdio>
using namespace std;
int N;
int manto[11];
bool dfs(int No, int sum)
{
int x = manto[10];
if(sum == 10){
return true;
}
else if(sum > 10)
return false;
for(int i = No; i > 0; i--){
if(manto[i] > 0){
manto[i]--;
if(!dfs(i,sum+i))
manto[i]++;
else{
if(No == 9)
manto[10]++;
return true;
}
}
}
return false;
}
int main()
{
while(cin >> N, N){
int a;
for(int i = 0; i <= 10; i++){
manto[i] = 0;
}
for(int i = 0; i < N; i++){
cin >> a;
manto[a]++;
}
for(int i = 0; i < 9; i++){
if(i == 5){
if(manto[i] >= 2){
while(manto[i] >= 2){
manto[i] -= 2;
manto[10]++;
}
}
}
else if(manto[i] > 0 && manto[10-i] > 0){
while(manto[i] > 0 && manto[10-i] > 0){
manto[i]--;
manto[10-i]--;
manto[10]++;
}
}
}
while(dfs(9,0));
printf("%d\n", manto[10])
}
return 0;
} | a.cc: In function 'int main()':
a.cc:70:42: error: expected ';' before '}' token
70 | printf("%d\n", manto[10])
| ^
| ;
71 | }
| ~
|
s673690288 | p00247 | C++ | #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
typedef pair<int, int> Pr;
typedef tuple<int, int, int> Tp;
#define at(t, i) get<i>(t)
int h, w;
int sx, sy, gx, gy;
char grid[14][14];
int dist[14][14];
int group[14][14];
int size[1024];
bool visit[14][14];
bool search(int x, int y, int d)
{
if (visit[x][y]) return false;
if (dist[x][y] > d) return false;
if (group[x][y] != -1 && size[group[x][y]] <= 1) return false;
if (x == gx && y == gy) return true;
visit[x][y] = true;
if (group[x][y] != -1) size[group[x][y]]--;
for (int dir = 0; dir < 4; dir++){
int nx = x + dx[dir];
int ny = y + dy[dir];
if (grid[nx][ny] == '#') continue;
if (visit[nx][ny]) continue;
if (search(nx, ny, d - 1)) return true;
}
visit[x][y] = false;
if (group[x][y] != -1) size[group[x][y]]++;
return false;
}
int solve()
{
int color = 0;
for (int i = 1; i <= h; i++){
for (int j = 1; j <= w; j++){
if (compl group[i][j]) continue;
if (grid[i][j] != 'X') continue;
size[color] = 1;
group[i][j] = color;
queue<Pr> que;
for (que.push(Pr(i, j)); que.size(); que.pop()){
Pr p = que.front();
int x = p.first, y = p.second;
for (int dir = 0; dir < 4; dir++){
int nx = x + dx[dir];
int ny = y + dy[dir];
if (group[nx][ny] == -1 && grid[nx][ny] == 'X'){
group[nx][ny] = color;
size[color]++;
que.push(Pr(nx, ny));
}
}
}
size[color] = size[color] / 2 + 1;
color++;
}
}
{
queue<Tp> que;
dist[gx][gy] = 0;
for (que.push(Tp(gx, gy, 0)); que.size(); que.pop()){
Tp t = que.front();
int x = at(t, 0), y = at(t, 1), d = at(t, 2);
for (int dir = 0; dir < 4; dir++){
int nx = x + dx[dir];
int ny = y + dy[dir];
if (grid[nx][ny] == '#') continue;
if (dist[nx][ny] < INF) continue;
dist[nx][ny] = d + 1;
que.push(Tp(nx, ny, d + 1));
}
}
}
for (int d = 1; ; d++){
if (search(sx, sy, d)) return d;
}
}
int main()
{
while (scanf("%d %d", &w, &h), h){
fill_n(*grid, 14 * 14, '#');
fill_n(*dist, 14 * 14, INF);
fill_n(*group, 14 * 14, -1);
fill_n(size, 1024, 0);
fill_n(*visit, 14 * 14, false);
for (int i = 1; i <= h; i++){
for (int j = 1; j <= w; j++){
scanf(" %c", &grid[i][j]);
if (grid[i][j] == 'S'){
sx = i;
sy = j;
grid[i][j] = '.';
}
else if (grid[i][j] == 'G'){
gx = i;
gy = j;
grid[i][j] = '.';
}
}
}
printf("%d\n", solve());
}
} | a.cc: In function 'bool search(int, int, int)':
a.cc:20:13: error: reference to 'visit' is ambiguous
20 | if (visit[x][y]) return false;
| ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
1855 | visit(_Visitor&& __visitor, _Variants&&... __variants)
| ^~~~~
a.cc:16:6: note: 'bool visit [14][14]'
16 | bool visit[14][14];
| ^~~~~
a.cc:22:34: error: reference to 'size' is ambiguous
22 | if (group[x][y] != -1 && size[group[x][y]] <= 1) return false;
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/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:15:5: note: 'int size [1024]'
15 | int size[1024];
| ^~~~
a.cc:26:9: error: reference to 'visit' is ambiguous
26 | visit[x][y] = true;
| ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
1855 | visit(_Visitor&& __visitor, _Variants&&... __variants)
| ^~~~~
a.cc:16:6: note: 'bool visit [14][14]'
16 | bool visit[14][14];
| ^~~~~
a.cc:27:32: error: reference to 'size' is ambiguous
27 | if (group[x][y] != -1) size[group[x][y]]--;
| ^~~~
/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:15:5: note: 'int size [1024]'
15 | int size[1024];
| ^~~~
a.cc:33:21: error: reference to 'visit' is ambiguous
33 | if (visit[nx][ny]) continue;
| ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
1855 | visit(_Visitor&& __visitor, _Variants&&... __variants)
| ^~~~~
a.cc:16:6: note: 'bool visit [14][14]'
16 | bool visit[14][14];
| ^~~~~
a.cc:37:9: error: reference to 'visit' is ambiguous
37 | visit[x][y] = false;
| ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
1855 | visit(_Visitor&& __visitor, _Variants&&... __variants)
| ^~~~~
a.cc:16:6: note: 'bool visit [14][14]'
16 | bool visit[14][14];
| ^~~~~
a.cc:38:32: error: reference to 'size' is ambiguous
38 | if (group[x][y] != -1) size[group[x][y]]++;
| ^~~~
/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:15:5: note: 'int size [1024]'
15 | int size[1024];
| ^~~~
a.cc: In function 'int solve()':
a.cc:50:25: error: reference to 'size' is ambiguous
50 | size[color] = 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:15:5: note: 'int size [1024]'
15 | int size[1024];
| ^~~~
a.cc:62:49: error: reference to 'size' is ambiguous
62 | size[color]++;
| ^~~~
/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:15:5: note: 'int size [1024]'
15 | int size[1024];
| ^~~~
a.cc:68:25: error: reference to 'size' is ambiguous
68 | size[color] = size[color] / 2 + 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:15:5: note: 'int size [1024]'
15 | int size[1024];
| ^~~~
a.cc:68:39: error: reference to 'size' is ambiguous
68 | size[color] = size[color] / 2 + 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:15:5: note: 'int size [1024]'
15 | int size[1024];
| ^~~~
a.cc: In function 'int main()':
a.cc:101:24: error: reference to 'size' is ambiguous
101 | fill_n(size, 1024, 0);
| ^~~~
/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:15:5: note: 'int size [1024]'
15 | int size[1024];
| ^~~~
a.cc:102:25: error: reference to 'visit' is ambiguous
102 | fill_n(*visit, 14 * 14, false);
| ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
1855 | visit(_Visitor&& __visitor, _Variants&&... __variants)
| ^~~~~
a.cc:16:6: note: 'bool visit [14][14]'
16 | bool visit[14][14];
| ^~~~~
|
s884109876 | p00247 | C++ | #include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> pii;
const int dxy[] = {1, 0, -1, 0, 1};
char maze[15][15];
int ice[15][15];
bitset<1000000> visited[12][12];
vector<int> icesq;
struct data {
int x, y;
int t, v;
data(int x_, int y_, int t_, int v_) {
x = x_;
y = y_;
t = t_;
v = v_;
}
};
int maketag(int i, int j, int n) {
if(maze[i][j] != 'X' || ice[i][j] != -1)
return 0;
ice[i][j] = n;
int res = 1;
for(int k = 0; k < 4; k++)
res += maketag(i+dxy[k], j+dxy[k+1], n);
return res;
}
int main() {
int x, y;
while(cin >> x >> y, x || y) {
for(int i = 0; i < 15; i++) {
for(int j = 0; j < 15; j++) {
maze[i][j] = '#';
ice[i][j] = -1;
}
}
for(int i = 0; i < y; i++) {
scanf("%s", maze[i+1]+1);
maze[i+1][1+x] = '#';
}
icesq.clear();
int tg = 0;
pii S, G;
for(int i = 0; i < y; i++) {
for(int j = 0; j < x; j++) {
int res;
if(maze[i+1][j+1] == 'S') {
maze[i+1][j+1] = '.';
S.fi = i+1; S.se = j+1;
}
else if(maze[i+1][j+1] == 'G') {
maze[i+1][j+1] = '.';
G.fi = i+1; G.se = j+1;
}
res = maketag(i+1,j+1,tg);
if(res != 0) {
icesq.push_back(res / 2);
tg++;
}
}
}
/*
for(int i = 0; i < 14; i++) {
for(int j = 0; j < 14; j++) {
cout << maze[i][j];
} cout << endl;
}
// */
/*
for(int i = 0; i < icesq.size(); i++) {
cout << icesq[i] << " ";
} cout << endl;
// */
queue<data> q;
q.push(data(S.se, S.fi, 0, 0));
vector<int> radix;
radix.resize(icesq.size() + 1);
radix[0] = 1;
for(int i = 1; i < radix.size(); i++) {
radix[i] = radix[i-1] * (icesq[i-1] + 1);
}
for(int i = 0; i < 12; i++) {
for(int j = 0; j < 12; j++) {
visited[i][j].reset();
}
}
while(!q.empty()) {
data cur = q.front();
q.pop();
// cout << cur.y << " " << cur.x << " " << cur.t << ":";
if(cur.y == G.fi && cur.x == G.se) {
cout << cur.t << endl;
break;
}
for(int i = 0; i < 4; i++) {
int nx, ny;
ny = cur.y + dxy[i];
nx = cur.x + dxy[i+1];
if(!(0 < nx && nx <= x && 0 < ny && ny <= y)) {
continue;
}
if(maze[ny][nx] == '.') {
if(!visited[ny-1][nx-1][cur.v]) {
visited[ny-1][nx-1][cur.v] = true;
q.push(data(nx, ny, cur.t + 1, cur.v));
}
}
else if(maze[ny][nx] == 'X') {
int flgcnts;
flgcnts = (cur.v % radix[ice[ny][nx]+1]) / radix[ice[ny][nx]];
if(flgcnts < icesq[ice[ny][nx]]) {
int tmp = cur.v + radix[ice[ny][nx]];
if(!visited[ny-1][nx-1][tmp]) {
visited[ny-1][nx-1][tmp] = true;
q.push(data(nx, ny, cur.t + 1, tmp));
}
}
}
}
}
// cout << "----------" << endl;
}
} | a.cc:18:1: error: 'bitset' does not name a type
18 | bitset<1000000> visited[12][12];
| ^~~~~~
a.cc: In function 'int main()':
a.cc:89:27: error: template argument 1 is invalid
89 | queue<data> q;
| ^
a.cc:89:27: error: template argument 2 is invalid
a.cc:90:19: error: request for member 'push' in 'q', which is of non-class type 'int'
90 | q.push(data(S.se, S.fi, 0, 0));
| ^~~~
a.cc:90:24: error: reference to 'data' is ambiguous
90 | q.push(data(S.se, S.fi, 0, 0));
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:8: note: 'struct data'
21 | struct data {
| ^~~~
a.cc:99:33: error: 'visited' was not declared in this scope
99 | visited[i][j].reset();
| ^~~~~~~
a.cc:102:26: error: request for member 'empty' in 'q', which is of non-class type 'int'
102 | while(!q.empty()) {
| ^~~~~
a.cc:103:25: error: reference to 'data' is ambiguous
103 | data cur = q.front();
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:8: note: 'struct data'
21 | struct data {
| ^~~~
a.cc:104:27: error: request for member 'pop' in 'q', which is of non-class type 'int'
104 | q.pop();
| ^~~
a.cc:106:28: error: 'cur' was not declared in this scope
106 | if(cur.y == G.fi && cur.x == G.se) {
| ^~~
a.cc:112:38: error: 'cur' was not declared in this scope
112 | ny = cur.y + dxy[i];
| ^~~
a.cc:120:45: error: 'visited' was not declared in this scope
120 | if(!visited[ny-1][nx-1][cur.v]) {
| ^~~~~~~
a.cc:122:51: error: request for member 'push' in 'q', which is of non-class type 'int'
122 | q.push(data(nx, ny, cur.t + 1, cur.v));
| ^~~~
a.cc:122:56: error: reference to 'data' is ambiguous
122 | q.push(data(nx, ny, cur.t + 1, cur.v));
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:8: note: 'struct data'
21 | struct data {
| ^~~~
a.cc:130:53: error: 'visited' was not declared in this scope
130 | if(!visited[ny-1][nx-1][tmp]) {
| ^~~~~~~
a.cc:132:59: error: request for member 'push' in 'q', which is of non-class type 'int'
132 | q.push(data(nx, ny, cur.t + 1, tmp));
| ^~~~
a.cc:132:64: error: reference to 'data' is ambiguous
132 | q.push(data(nx, ny, cur.t + 1, tmp));
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:21:8: note: 'struct data'
21 | struct data {
| ^~~~
|
s073862902 | p00247 | C++ | #include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
#include <bitset>
using namespace std;
#define fi first
#define se second
typedef pair<int,int> pii;
const int dxy[] = {1, 0, -1, 0, 1};
char maze[15][15];
int ice[15][15];
bit set<3000000> visited[12][12];
vector<int> icesq;
struct data {
int x, y;
int t, v;
data(int x_, int y_, int t_, int v_) {
x = x_;
y = y_;
t = t_;
v = v_;
}
};
int maketag(int i, int j, int n) {
if(maze[i][j] != 'X' || ice[i][j] != -1)
return 0;
ice[i][j] = n;
int res = 1;
for(int k = 0; k < 4; k++)
res += maketag(i+dxy[k], j+dxy[k+1], n);
return res;
}
int main() {
int x, y;
while(cin >> x >> y, x || y) {
for(int i = 0; i < 15; i++) {
for(int j = 0; j < 15; j++) {
maze[i][j] = '#';
ice[i][j] = -1;
}
}
for(int i = 0; i < y; i++) {
scanf("%s", maze[i+1]+1);
maze[i+1][1+x] = '#';
}
icesq.clear();
int tg = 0;
pii S, G;
for(int i = 0; i < y; i++) {
for(int j = 0; j < x; j++) {
int res;
if(maze[i+1][j+1] == 'S') {
maze[i+1][j+1] = '.';
S.fi = i+1; S.se = j+1;
}
else if(maze[i+1][j+1] == 'G') {
maze[i+1][j+1] = '.';
G.fi = i+1; G.se = j+1;
}
res = maketag(i+1,j+1,tg);
if(res != 0) {
icesq.push_back(res / 2);
tg++;
}
}
}
/*
for(int i = 0; i < 14; i++) {
for(int j = 0; j < 14; j++) {
cout << maze[i][j];
} cout << endl;
}
// */
/*
for(int i = 0; i < icesq.size(); i++) {
cout << icesq[i] << " ";
} cout << endl;
// */
queue<data> q;
q.push(data(S.se, S.fi, 0, 0));
vector<int> radix;
radix.resize(icesq.size() + 1);
radix[0] = 1;
for(int i = 1; i < radix.size(); i++) {
radix[i] = radix[i-1] * (icesq[i-1] + 1);
}
for(int i = 0; i < 12; i++) {
for(int j = 0; j < 12; j++) {
visited[i][j].reset();
}
}
while(!q.empty()) {
data cur = q.front();
q.pop();
// cout << cur.y << " " << cur.x << " " << cur.t << ":";
if(cur.y == G.fi && cur.x == G.se) {
cout << cur.t << endl;
break;
}
for(int i = 0; i < 4; i++) {
int nx, ny;
ny = cur.y + dxy[i];
nx = cur.x + dxy[i+1];
if(!(0 < nx && nx <= x && 0 < ny && ny <= y)) {
continue;
}
if(maze[ny][nx] == '.') {
if(!visited[ny-1][nx-1][cur.v]) {
visited[ny-1][nx-1][cur.v] = true;
q.push(data(nx, ny, cur.t + 1, cur.v));
}
}
else if(maze[ny][nx] == 'X') {
int flgcnts;
flgcnts = (cur.v % radix[ice[ny][nx]+1]) / radix[ice[ny][nx]];
if(flgcnts < icesq[ice[ny][nx]]) {
int tmp = cur.v + radix[ice[ny][nx]];
if(!visited[ny-1][nx-1][tmp]) {
visited[ny-1][nx-1][tmp] = true;
q.push(data(nx, ny, cur.t + 1, tmp));
}
}
}
}
}
// cout << "----------" << endl;
}
} | a.cc:19:1: error: 'bit' does not name a type
19 | bit set<3000000> visited[12][12];
| ^~~
a.cc: In function 'int main()':
a.cc:90:27: error: template argument 1 is invalid
90 | queue<data> q;
| ^
a.cc:90:27: error: template argument 2 is invalid
a.cc:91:19: error: request for member 'push' in 'q', which is of non-class type 'int'
91 | q.push(data(S.se, S.fi, 0, 0));
| ^~~~
a.cc:91:24: error: reference to 'data' is ambiguous
91 | q.push(data(S.se, S.fi, 0, 0));
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:22:8: note: 'struct data'
22 | struct data {
| ^~~~
a.cc:100:33: error: 'visited' was not declared in this scope
100 | visited[i][j].reset();
| ^~~~~~~
a.cc:103:26: error: request for member 'empty' in 'q', which is of non-class type 'int'
103 | while(!q.empty()) {
| ^~~~~
a.cc:104:25: error: reference to 'data' is ambiguous
104 | data cur = q.front();
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:22:8: note: 'struct data'
22 | struct data {
| ^~~~
a.cc:105:27: error: request for member 'pop' in 'q', which is of non-class type 'int'
105 | q.pop();
| ^~~
a.cc:107:28: error: 'cur' was not declared in this scope
107 | if(cur.y == G.fi && cur.x == G.se) {
| ^~~
a.cc:113:38: error: 'cur' was not declared in this scope
113 | ny = cur.y + dxy[i];
| ^~~
a.cc:121:45: error: 'visited' was not declared in this scope
121 | if(!visited[ny-1][nx-1][cur.v]) {
| ^~~~~~~
a.cc:123:51: error: request for member 'push' in 'q', which is of non-class type 'int'
123 | q.push(data(nx, ny, cur.t + 1, cur.v));
| ^~~~
a.cc:123:56: error: reference to 'data' is ambiguous
123 | q.push(data(nx, ny, cur.t + 1, cur.v));
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:22:8: note: 'struct data'
22 | struct data {
| ^~~~
a.cc:131:53: error: 'visited' was not declared in this scope
131 | if(!visited[ny-1][nx-1][tmp]) {
| ^~~~~~~
a.cc:133:59: error: request for member 'push' in 'q', which is of non-class type 'int'
133 | q.push(data(nx, ny, cur.t + 1, tmp));
| ^~~~
a.cc:133:64: error: reference to 'data' is ambiguous
133 | q.push(data(nx, ny, cur.t + 1, tmp));
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:22:8: note: 'struct data'
22 | struct data {
| ^~~~
|
s779749414 | p00247 | C++ | #include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int,int> P;
struct edge{int to,cost;};
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
char field[12][12];
int ifield[12][12];
int W,H;
struct State{
int d,y,x;
vec ice;
bool operator<(const State& right) const{
return d == right.d ? ice > right.ice : d > right.d;
}
};
string state2str(State& s){
string ret = "";
ret.push_back(s.d+'0');
ret.push_back(s.y+'0');
ret.push_back(s.x+'0');
for(int i=0;i<s.ice.size();i++){
ret.push_back(s.ice[i]+'0');
}
return ret;
}
int lump_ice_num;
int ice_num[12*12];
int dfs(int y, int x){
int ret = 1;
ifield[y][x] = lump_ice_num;
field[y][x] = '.';
for(int i=0;i<4;i++){
int ny = y+dy[i], nx = x+dx[i];
if(ny<0||H<=ny||nx<0||W<=nx)continue;
if(field[ny][nx]=='X'){
ret += dfs(ny, nx);
}
}
return ret;
}
int main(){
while(cin >> W >> H, W){
int sy, sx, gy, gx;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin >> field[i][j];
if(field[i][j]=='.'){
ifield[i][j] = -1;
}else if(field[i][j]=='#'){
ifield[i][j] = -2;
}else if(field[i][j]=='S'){
ifield[i][j] = -1;
sy = i; sx = j;
}else if(field[i][j]=='G'){
ifield[i][j] = -1;
gy = i; gx = j;
}
}
}
lump_ice_num = 0;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(field[i][j]=='X'){
ice_num[lump_ice_num] = dfs(i,j);
lump_ice_num++;
}
}
}
priority_queue<State> que;
que.push((State){0,sy,sx,vec(lump_ice_num, 0)});
set<string> visited;
while(que.size()){
State p = que.front(); que.pop();
string state_str = state2str(p);
if(visited.count(state_str)) continue;
visited.insert(state_str);
//cout << state_str << endl;
if(p.y==gy&&p.x==gx){
cout << p.d << endl;
break;
}
for(int i=0;i<4;i++){
int ny = p.y + dy[i], nx = p.x + dx[i];
vec nice = p.ice;
if(ny<0||H<=ny||nx<0||W<=nx)continue;
if(ifield[ny][nx]==-2)continue;
if(ifield[ny][nx]>=0){
int ice_i = ifield[ny][nx];
if(ice_num[ice_i]/2 < nice[ice_i]+1) continue;
nice[ice_i]++;
}
State np = (State){p.d+1,ny,nx,nice};
string nstr = state2str(np);
if(visited.count(nstr)==0){
que.push(np);
}
}
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:99:27: error: 'class std::priority_queue<State>' has no member named 'front'
99 | State p = que.front(); que.pop();
| ^~~~~
|
s052989578 | p00247 | C++ | #include <algorithm>
#include <iostream>
#include <queue>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)
int h, w;
char field[16][16];
int label[16][16];
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};
int labeling(int y, int x, int l)
{
int ret = 1;
label[y][x] = l;
rep(i, 4){
int py = y + dy[i];
int px = x + dx[i];
if(py<0 || h<=py || px<0 || w<=px) continue;
if(field[py][px] == 'X' && label[py][px] == 0){
ret += labeling(py, px, l);
}
}
return ret;
}
struct Data
{
int y, x, cost;
vi broken;
bool operator== (const Data& d) const
{
return y == d.y && x == d.x && broken == d.broken;
}
};
template<>
struct hash<Data>
{
size_t operator()(const Data& d) const
{
size_t h = d.y ^ d.x;
rep(i, d.broken.size()) h ^= d.broken[i] << i;
return h;
}
};
int func()
{
rep(i, h) rep(j, w) label[i][j] = 0;
rep(i, h){
cin >> field[i];
}
vi area;
rep(y, h) rep(x, w){
if(field[y][x] == 'X' && label[y][x] == 0){
area.push_back(labeling(y, x, area.size() + 1));
}
}
for(int& a : area){
a /= 2;
}
queue<Data> Q;
unordered_set<Data> visited;
rep(y, h) rep(x, w){
if(field[y][x] == 'S'){
Q.push({y, x, 0, area});
visited.insert(Q.front());
}
}
while(!Q.empty()){
Data d = Q.front();
Q.pop();
rep(i, 4){
int py = d.y + dy[i];
int px = d.x + dx[i];
if(py<0 || h<=py || px<0 || w<=px || field[py][px] == '#') continue;
Data next;
if(field[py][px] == 'G'){
return d.cost + 1;
}
else if(field[py][px] == 'X'){
int& b = d.broken[label[py][px]-1];
if(b == 0) continue;
--b;
next = {py, px, d.cost + 1, d.broken};
++b;
}
else{
next = {py, px, d.cost + 1, d.broken};
}
if(visited.count(next)) continue;
Q.push(next);
visited.insert(next);
}
}
return 0;
}
int main()
{
while(cin >> w >> h, w){
printf("%d\n", func());
}
} | a.cc:53:8: error: explicit specialization of 'template<class _Tp> struct std::hash' outside its namespace must use a nested-name-specifier [-fpermissive]
53 | struct hash<Data>
| ^~~~~~~~~~
|
s102652848 | p00247 | C++ | #include<iostream>
#include<stack>
#include<queue>
#include<cstring>
#define INF 1 << 15
using namespace std;
struct d{
int x;
int y;
int visited[12][12];
int ic[144];
int cnt;
};
struct b{
int x;
int y;
};
int main(){
int lx,ly,i,j,nc=1,k,a,min=144,gx,gy,ex,ey;
int maps[12][12]={0};
int mx[4]={-1,0,1,0};
int my[4]={0,-1,0,1};
int ig[144]={0};
int f[12][12];
int mapc[13][13];
char map[13][13];
queue<b> q;
b v,u;
stack<d> s;
d r,t;
while(1){
cin>>lx>>ly;
if(lx==0&&ly==0){
break;
}
memset(mapc,-1,sizeof(mapc));
nc=1;
memset(maps,0,sizeof(maps));
memset(ig,0,sizeof(ig));
min=144;
for(i=0;i<ly;i++){
cin>>map[i];
}
for(i=0;i<ly;i++){
for(j=0;j<lx;j++){
if(map[i][j]=='S'){
r.x=j;
r.y=i;
memset(r.visited,0,sizeof(r.visited));
memset(r.ic,0,sizeof(r.ic));
r.cnt=0;
mapc[i][j]=0;
s.push(r);
}
if(map[i][j]=='G'){
gx=j;
gy=i;
}
if(map[i][j]=='X'&&maps[i][j]==0){
v.x=j;
v.y=i;
q.push(v);
while(!q.empty()){
v=q.front();
q.pop();
maps[v.y][v.x]=nc;
ig[nc]++;
for(k=0;k<4;k++){
u=v;
u.x+=mx[k];
u.y+=my[k];
if(map[u.y][u.x]=='X'&&maps[u.y][u.x]==0&&u.x>=0&&u.x<lx&&u.y>=0&&u.y<ly){
q.push(u);
}
}
}
if(ig[nc]==1){
map[v.y][v.x]='#';
}
nc++;
}
}
}
v.x=gx;
v.y=gy;
memset(f,-1,sizeof(f));
f[gy][gx]=0;
q.push(v);
while(!q.empty()){
v=q.front();
q.pop();
for(i=0;i<4;i++){
u=v;
u.x+=mx[i];
u.y+=my[i];
if(map[u.y][u.x]!='#'&&u.x>=0&&u.x<lx&&u.y>=0&&u.y<ly&&f[u.y][u.x]==-1){
q.push(u);
f[u.y][u.x]=f[v.y][v.x]+1;
}
}
}
while(!s.empty()){
r=s.top();
s.pop();
if(r.visited[r.y][r.x]==1){
continue;
}
else{
r.visited[r.y][r.x]=1;
}
if(r.cnt+f[r.y][r.x]>=min){
continue;
}
for(i=0;i<4;i++){
t=r;
t.x+=mx[i];
t.y+=my[i];
t.cnt++;
if(map[t.y][t.x]!='#'&&t.x>=0&&t.x<lx&&t.y>=0&&t.y<ly){
if(mapc[t.y][t.x]>r.cnt+1||mapc[t.y][t.x]==-1){
mapc[t.y][t.x]=r.cnt+1;
}
else{
if(mapc[t.y][t.x]=<r.cnt){
continue;
}
}
if(map[t.y][t.x]=='G'&&t.cnt<min&&t.x>=0&&t.x<lx&&t.y>=0&&t.y<ly){
ex=t.x;
ey=t.y;
min=t.cnt;
break;
}
else if(r.visited[t.y][t.x]==0){
if(map[t.y][t.x]=='X'){
a=maps[t.y][t.x];
t.ic[a]++;
if(t.ic[a]<=(ig[a]/2)){
s.push(t);
}
}
else{
s.push(t);
}
}
}
}
}
cout<<mapc[ey][ex]<<endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:130:67: error: expected primary-expression before '<' token
130 | if(mapc[t.y][t.x]=<r.cnt){
| ^
|
s689381819 | p00247 | C++ | #include<bits/stdc++.h>
using namespace std;
int W, H;
char map[16][16];
char g[16][16];
bool v[16][16];
int maxIce[128];
int ice[128];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int ans;
int px, py;
int sx, sy, gx, gy;
bool getMin(int ty, int tx, int turn){
if (turn + abs(ty - gy) + abs(tx - gx) >= ans){return (false);}
if (ty == gy && tx == gx){
ans = turn; return (true);
}
for (int i = 0; i < 4; i++){int mx = tx + dx[i], my = ty + dy[i];
if (0 <= mx && mx < W && 0 <= my && my < H && px != mx && py != my && v[my][mx]){
return (false);
}
}
for (int i = 0; i < 4; i++){
int mx = tx + dx[i], my = ty + dy[i]; px = tx, py = ty;
if (0 <= mx && mx < W && 0 <= my && my < H && map[my][mx] != '#' && !v[my][mx]){
if (g[my][mx] == -1){
v[my][mx] = true;
if (getMin(my, mx, turn + 1)) return (true);
v[my][mx] = false;
}
else if (maxIce[g[my][mx]] >= ice[g[my][mx]] + 1){
ice[g[my][mx]]++;
v[my][mx] = true;
if (getMin(my, mx, turn + 1)) return (true);
v[my][mx] = false;
ice[g[my][mx]]--;
}
}
}
return (false);
}
void label(int ty, int tx, int p){
g[ty][tx] = p;
maxIce[p]++;
for (int i = 0; i < 4; i++){
int mx = tx + dx[i], my = ty + dy[i];
if (0 <= mx && mx < W && 0 <= my && my < H &&map[my][mx] == 'X' && g[my][mx] == -1){
label(my, mx, p);
}
}
}
int main(){
int idx;
while (1){scanf("%d %d", &W, &H);
if (W + H == 0){break;}
for (int i = 0; i < H; i++){ scanf("%s", map[i]);
for (int j = 0; j < W; j++){
if (map[i][j] == 'S'){map[i][j] = '.';sx = j, sy = i;}
if (map[i][j] == 'G'){map[i][j] = '.';gx = j, gy = i;}
}
}
memset(g, -1, sizeof(g)); memset(maxIce, 0, sizeof(maxIce));
idx = 0;
for (int i = 0; i < H; i++){ for (int j = 0; j < W; j++){
if (map[i][j] == 'X' && g[i][j] == -1){label(i, j, idx);maxIce[idx++] /= 2;}}
}
memset(ice, 0, sizeof(ice)); memset(v, 0, sizeof(v));
px = py = -1; v[sy][sx] = true; ans = 0;
while (!getMin(sy, sx, 0)){
memset(ice, 0, sizeof(ice));
memset(v, 0, sizeof(v));
px = py = -1;
v[sy][sx] = true;
ans++;
}
printf("%d\n", ans);
}
return (0);
} | a.cc: In function 'bool getMin(int, int, int)':
a.cc:27:55: error: reference to 'map' is ambiguous
27 | if (0 <= mx && mx < W && 0 <= my && my < H && map[my][mx] != '#' && !v[my][mx]){
| ^~~
In file included from /usr/include/c++/14/map:63,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:4:6: note: 'char map [16][16]'
4 | char map[16][16];
| ^~~
a.cc: In function 'void label(int, int, int)':
a.cc:50:54: error: reference to 'map' is ambiguous
50 | if (0 <= mx && mx < W && 0 <= my && my < H &&map[my][mx] == 'X' && g[my][mx] == -1){
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:4:6: note: 'char map [16][16]'
4 | char map[16][16];
| ^~~
a.cc: In function 'int main()':
a.cc:60:50: error: reference to 'map' is ambiguous
60 | for (int i = 0; i < H; i++){ scanf("%s", map[i]);
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:4:6: note: 'char map [16][16]'
4 | char map[16][16];
| ^~~
a.cc:62:21: error: reference to 'map' is ambiguous
62 | if (map[i][j] == 'S'){map[i][j] = '.';sx = j, sy = i;}
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:4:6: note: 'char map [16][16]'
4 | char map[16][16];
| ^~~
a.cc:62:39: error: reference to 'map' is ambiguous
62 | if (map[i][j] == 'S'){map[i][j] = '.';sx = j, sy = i;}
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:4:6: note: 'char map [16][16]'
4 | char map[16][16];
| ^~~
a.cc:63:21: error: reference to 'map' is ambiguous
63 | if (map[i][j] == 'G'){map[i][j] = '.';gx = j, gy = i;}
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:4:6: note: 'char map [16][16]'
4 | char map[16][16];
| ^~~
a.cc:63:39: error: reference to 'map' is ambiguous
63 | if (map[i][j] == 'G'){map[i][j] = '.';gx = j, gy = i;}
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:4:6: note: 'char map [16][16]'
4 | char map[16][16];
| ^~~
a.cc:69:21: error: reference to 'map' is ambiguous
69 | if (map[i][j] == 'X' && g[i][j] == -1){label(i, j, idx);maxIce[idx++] /= 2;}}
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:4:6: note: 'char map [16][16]'
4 | char map[16][16];
| ^~~
|
s575813060 | p00247 | C++ | #include<bits/stdc++.h>
using namespace std;
int W, H;
char map[16][16];
char g[16][16];
bool v[16][16];
int maxIce[128];
int ice[128];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int ans;
int px, py;
int sx, sy, gx, gy;
bool getMin(int ty, int tx, int turn)
{
if (turn + abs(ty - gy) + abs(tx - gx) >= ans){
return (false);
}
if (ty == gy && tx == gx){
ans = turn;
return (true);
}
for (int i = 0; i < 4; i++){
int mx = tx + dx[i], my = ty + dy[i];
if (0 <= mx && mx < W && 0 <= my && my < H && px != mx && py != my && v[my][mx]){
return (false);
}
}
for (int i = 0; i < 4; i++){
int mx = tx + dx[i], my = ty + dy[i];
px = tx, py = ty;
if (0 <= mx && mx < W && 0 <= my && my < H && map[my][mx] != '#' && !v[my][mx]){
if (g[my][mx] == -1){
v[my][mx] = true;
if (getMin(my, mx, turn + 1)) return (true);
v[my][mx] = false;
}
else if (maxIce[g[my][mx]] >= ice[g[my][mx]] + 1){
ice[g[my][mx]]++;
v[my][mx] = true;
if (getMin(my, mx, turn + 1)) return (true);
v[my][mx] = false;
ice[g[my][mx]]--;
}
}
}
return (false);
}
void label(int ty, int tx, int p)
{
g[ty][tx] = p;
maxIce[p]++;
for (int i = 0; i < 4; i++){
int mx = tx + dx[i], my = ty + dy[i];
if (0 <= mx && mx < W && 0 <= my && my < H &&
map[my][mx] == 'X' && g[my][mx] == -1){
label(my, mx, p);
}
}
}
int main()
{
int idx;
while (1){
scanf("%d %d", &W, &H);
if (W + H == 0){
break;
}
for (int i = 0; i < H; i++){
scanf("%s", map[i]);
for (int j = 0; j < W; j++){
if (map[i][j] == 'S'){
map[i][j] = '.';
sx = j, sy = i;
}
if (map[i][j] == 'G'){
map[i][j] = '.';
gx = j, gy = i;
}
}
}
memset(g, -1, sizeof(g));
memset(maxIce, 0, sizeof(maxIce));
idx = 0;
for (int i = 0; i < H; i++){
for (int j = 0; j < W; j++){
if (map[i][j] == 'X' && g[i][j] == -1){
label(i, j, idx);
maxIce[idx++] /= 2;
}
}
}
memset(ice, 0, sizeof(ice));
memset(v, 0, sizeof(v));
px = py = -1;
v[sy][sx] = true;
ans = 0;
while (!getMin(sy, sx, 0)){
memset(ice, 0, sizeof(ice));
memset(v, 0, sizeof(v));
px = py = -1;
v[sy][sx] = true;
ans++;
}
printf("%d\n", ans);
}
return (0);
} | a.cc: In function 'bool getMin(int, int, int)':
a.cc:44:55: error: reference to 'map' is ambiguous
44 | if (0 <= mx && mx < W && 0 <= my && my < H && map[my][mx] != '#' && !v[my][mx]){
| ^~~
In file included from /usr/include/c++/14/map:63,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:8:6: note: 'char map [16][16]'
8 | char map[16][16];
| ^~~
a.cc: In function 'void label(int, int, int)':
a.cc:72:21: error: reference to 'map' is ambiguous
72 | map[my][mx] == 'X' && g[my][mx] == -1){
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:8:6: note: 'char map [16][16]'
8 | char map[16][16];
| ^~~
a.cc: In function 'int main()':
a.cc:90:25: error: reference to 'map' is ambiguous
90 | scanf("%s", map[i]);
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:8:6: note: 'char map [16][16]'
8 | char map[16][16];
| ^~~
a.cc:92:21: error: reference to 'map' is ambiguous
92 | if (map[i][j] == 'S'){
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:8:6: note: 'char map [16][16]'
8 | char map[16][16];
| ^~~
a.cc:93:21: error: reference to 'map' is ambiguous
93 | map[i][j] = '.';
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:8:6: note: 'char map [16][16]'
8 | char map[16][16];
| ^~~
a.cc:96:21: error: reference to 'map' is ambiguous
96 | if (map[i][j] == 'G'){
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:8:6: note: 'char map [16][16]'
8 | char map[16][16];
| ^~~
a.cc:97:21: error: reference to 'map' is ambiguous
97 | map[i][j] = '.';
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:8:6: note: 'char map [16][16]'
8 | char map[16][16];
| ^~~
a.cc:109:21: error: reference to 'map' is ambiguous
109 | if (map[i][j] == 'X' && g[i][j] == -1){
| ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
102 | class map
| ^~~
a.cc:8:6: note: 'char map [16][16]'
8 | char map[16][16];
| ^~~
|
s163443311 | p00247 | C++ | #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int W,H,SX,SY,GX,GY,ice_N;
int field[14][14],ice[14][14],icelife[1000];
bool flag[14][14];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
void dfs(int x, int y);
bool iddfs(int x, int y, int c);
int main(){
while(cin >>W>>H,W||H){
for(int i=0; i<14; i++){for(int j=0; j<14; j++){field[i][j] = 1;flag[i][j] = true;}}
memset(ice,0,sizeof(ice));
memset(icelife,0,sizeof(icelife));
ice_N = 1;
string s;
int ans;
for(int i=1; i<=H; i++){
cin >>s;
for(int j=1; j<=W; j++){
if(s[j-1] == '.'){field[j][i] = 0;}
if(s[j-1] == '#'){field[j][i] = 1;}
if(s[j-1] == 'X'){field[j][i] = 2;}
if(s[j-1] == 'S'){field[j][i] = 0;SX = j;SY = i;}
if(s[j-1] == 'G'){field[j][i] = 0;GX = j;GY = i;}
}
}
for(int i=1; i<=W; i++){
for(int j=1; j<=H; j++){
if(field[i][j] == 2 && ice[i][j] == 0){
dfs(i,j);
icelife[ice_N]/=2;
ice_N++;
}
}
}
for(ans = 0;;ans++){
if(iddfs(SX,SY,ans)){cout <<ans+1<<endl;break;}
}
}
return 0;
}
void dfs(int x, int y){
ice[x][y] = ice_N;
icelife[ice_N]++;
for(int i=0; i<4; i++){
int p = x+dx[i],q = y+dy[i];
if(field[p][q] == 2 && ice[p][q] == 0){dfs(p,q);}
}
}
bool iddfs(int x, int y, int c){
bool f = false;
if(x == GX && y == GY){return true;}
if(c<0){return false;}
for(int i=0; i<4; i++){
int p = x+dx[i],q = y+dy[i];
if(flag[p][q]){
if(field[p][q] == 0){
flag[p][q] = false;
if(iddfs(p,q,c-1)){f = true;}
flag[p][q] = true;
}
if(field[p][q] == 2){
if(icelife[ice[p][q]]>0){
flag[p][q] = false;
icelife[ice[p][q]]--;
if(iddfs(p,q,c-1)){f = true;}
icelife[ice[p][q]]++;
flag[p][q] = true;
}
}
}
}
return f;
} | a.cc: In function 'int main()':
a.cc:15:5: error: 'memset' was not declared in this scope
15 | memset(ice,0,sizeof(ice));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include<algorithm>
+++ |+#include <cstring>
4 | using namespace std;
|
s983781807 | p00247 | C++ | #include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;
const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
const int inf = (int) 1e9;
int h, w, sy, sx, gy, gx;
string in[100];
set<pair<vi, int> > s;
int p[200], sz[200], size[200], dist[200][200];
int root(int x){ return x == p[x] ? x : (p[x] = root(p[x])); }
int main(){
while(cin >> w >> h, w){
rep(i, h){
cin >> in[i];
rep(j, w){
if(in[i][j] == 'S') sy = i, sx = j;
if(in[i][j] == 'G') gy = i, gx = j;
}
}
rep(i, 200) p[i] = i, sz[i] = 1;
rep(i, 200) rep(j, 200) dist[i][j] = inf;
rep(i, h) rep(j, w) if(in[i][j] != '#'){
rep(d, 4){
int y = i + dy[d], x = j + dx[d];
if(y < 0 || y >= h || x < 0 || x >= w) continue;
if(in[y][x] != '#'){
dist[i * w + j][y * w + x] = 1;
}
}
}
rep(k, 200) rep(i, 200) rep(j, 200)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
rep(i, h) rep(j, w) if(in[i][j] == 'X'){
rep(d, 4){
int y = i + dy[d], x = j + dx[d];
if(y < 0 || y >= h || x < 0 || x >= w) continue;
if(in[y][x] == 'X'){
int a = root(y * w + x), b = root(i * w + j);
if(a != b) p[b] = a, sz[a] += sz[b];
}
}
}
map<int, int> of;
rep(i, h) rep(j, w) if(in[i][j] == 'X'){
of[root(i * w + j)] = 0;
}
int k = 0;
each(i, of){
i->second = k++;
size[i->second] = sz[i->first];
}
vi v(k);
s.clear();
priority_queue<pair<pi, pair<vi, int> > > q;
q.push(mp(mp(-dist[gy * w + gx][sy * w + sx], 0), mp(v, sy * w + sx)));
while(!q.empty()){
int y = q.top().second.second / w, x = q.top().second.second % w;
int c = q.top().first.second;
v = q.top().second.first;
q.pop();
if(s.count(mp(v, y * w + x))) continue;
s.insert(mp(v, y * w + x));
if(in[y][x] == 'G'){
cout << -c << endl;
break;
}
rep(d, 4){
int ny = y + dy[d], nx = x + dx[d];
if(ny < 0 || ny >= h || nx < 0 || nx >= w || in[ny][nx] == '#') continue;
vi nv = v;
if(in[ny][nx] == 'X'){
int t = of[root(ny * w + nx)];
nv[t]++;
if(2 * nv[t] > size[t]) continue;
}
q.push(mp(mp(-dist[gy * w + gx][ny * w + nx] + c, c - 1), mp(nv, ny * w + nx)));
}
}
}
} | a.cc:29:11: error: redefinition of 'const int inf'
29 | const int inf = (int) 1e9;
| ^~~
a.cc:25:11: note: 'const int inf' previously defined here
25 | const int inf=(int)1e9;
| ^~~
a.cc: In function 'int main()':
a.cc:80:25: error: reference to 'size' is ambiguous
80 | size[i->second] = sz[i->first];
| ^~~~
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:35:22: note: 'int size [200]'
35 | int p[200], sz[200], size[200], dist[200][200];
| ^~~~
a.cc:110:56: error: reference to 'size' is ambiguous
110 | if(2 * nv[t] > size[t]) continue;
| ^~~~
/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:35:22: note: 'int size [200]'
35 | int p[200], sz[200], size[200], dist[200][200];
| ^~~~
|
s122305874 | p00247 | C++ | #include <iostream>
#include <unordered_set>
#include <string>
#include <array>
#include <vector>
#include <queue>
using namespace std;
typedef unsigned long long ULL;
int ORD, N;
ULL h(const vector<int> &v, int y, int x) {
ULL res = 0;
for(int i : v) {
res *= ORD;
res += i;
}
res *= 12;
res += y;
res *= 12;
res += x;
return res;
}
void d(ULL val, vector<int> &v, int &y, int &x) {
v.resize(N, 0);
x = val % 12;
val /= 12;
y = val % 12;
val /= 12;
for(int i = v.size()-1; i >= 0; --i) {
v[i] = val % ORD;
val /= ORD;
}
}
const int DY[] = {0, -1, 0, 1};
const int DX[] = {1, 0, -1, 0};
inline bool in_range(int a, int x, int b) {
return a <= x && x < b;
}
int X, Y;
int bfs(vector<string> &v, int y, int x, array<array<int,12>,12> &field, int label) {
int cnt = 0;
queue<pair<int,int>> q;
q.push(make_pair(y, x));
while(!q.empty()) {
int cy = q.front().first;
int cx = q.front().second;
q.pop();
v[cy][cx] = '$';
field[cy][cx] = label;
++cnt;
for(int i = 0; i < 4; ++i) {
const int ny = cy + DY[i];
const int nx = cx + DX[i];
if(in_range(0, ny, Y) && in_range(0, nx, X) && v[ny][nx] == 'X') {
q.push(make_pair(ny, nx));
}
}
}
return cnt;
}
bool solve() {
cin >> X >> Y;
if(!X && !Y) return false;
vector<string> v(Y);
for(string &s : v) {
cin >> s;
}
array<array<int,12>,12> field;
pair<int,int> start, goal;
vector<int> ice;
ice.push_back(0);
for(int y = 0; y < Y; ++y) {
for(int x = 0; x < X; ++x) {
if(v[y][x] == 'X') {
int cnt = bfs(v, y, x, field, -(int)ice.size());
if(cnt == 1) {
field[y][x] = 0;
} else {
ice.push_back(cnt/2);
}
} else if(v[y][x] == '#') {
field[y][x] = 0;
} else if(v[y][x] != '$') {
field[y][x] = 1;
if(v[y][x] == 'S') {
start = make_pair(y, x);
} else if(v[y][x] == 'G') {
goal = make_pair(y, x);
}
}
}
}
N = ice.size();
ORD = *max_element(ice.begin(), ice.end())+1;
vector<int> state(N, 0);
vector<ULL> q[2];
unordered_set<ULL> memo;
q[0].push_back(h(state, start.first, start.second));
memo.insert(q[0].back());
int turn = 0;
while(q[0].size() > 0) {
q[1].clear();
for(const auto &s : q[0]) {
int x, y;
d(s, state, y, x);
//cout << turn << ": " << x << ' ' << y << ' ' << "s " << state[1] << endl;
if(y == goal.first && x == goal.second) {
goto end;
}
for(int i = 0; i < 4; ++i) {
const int ny = y + DY[i];
const int nx = x + DX[i];
if(in_range(0, ny, Y) && in_range(0, nx, X)) {
if(field[ny][nx] < 0) {
const int idx = -field[ny][nx];
if(state[idx] >= ice[idx]) continue;
state[idx]++;
const ULL nh = h(state, ny, nx);
if(memo.count(nh) == 0) {
memo.insert(nh);
q[1].push_back(nh);
}
state[idx]--;
} else if(field[ny][nx] == 1) {
const ULL nh = h(state, ny, nx);
if(memo.count(nh) == 0) {
memo.insert(nh);
q[1].push_back(nh);
}
}
}
}
}
++turn;
q[0].swap(q[1]);
}
end:
cout << turn << endl;
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
while(solve()) ;
return 0;
} | a.cc: In function 'bool solve()':
a.cc:104:12: error: 'max_element' was not declared in this scope
104 | ORD = *max_element(ice.begin(), ice.end())+1;
| ^~~~~~~~~~~
|
s852970727 | p00247 | C++ | #include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<queue>
#include<cassert>
#include<deque>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define all(n) (n).begin(),(n).end()
#define MAX 12
using namespace std;
struct Pox
{
vector<int> array;
int cost;
Pox(vector<int> array=vector<int>(),int cost=inf):array(array),cost(cost){}
bool operator < (const Pox &a)const
{
return cost > a.cost;
}
};
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
//int dx[] = {0,1,0,-1};
//int dy[] = {1,0,-1,0};
//int ev[MAX*MAX][MAX*MAX];//評価値 ev[a][b] := aからbまでの最短コスト
char g[MAX][MAX];
int st[2],h,w,ice_number,T;
int ice[MAX*MAX];
int ice_cnt[MAX*MAX];
set<vector<int> > mincost;
void init()
{
ice_number = 0;
rep(i,h)rep(j,w)ice[j+i*w] = ice_cnt[j+i*w] = inf;
//rep(i,h*w)rep(j,h*w)ev[i][j] = inf;
mincost.clear();
}
void getInput()
{
rep(i,h)
{
getchar();
rep(j,w)
{
scanf("%c",&g[i][j]);
if(g[i][j] == 'S')
{
st[1] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == 'G')
{
st[0] = j + i * w;
g[i][j] = '.';
}
}
}
}
void make_ev()
{
rep(sp,h*w)
{
ev[sp][sp] = 0;
deque<int> deq;
deq.push_back(sp);
while(!deq.empty())
{
int cur = deq.front(); deq.pop_front();
rep(i,4)
{
int nx = cur % w + dx[i];
int ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
if(ev[sp][nx+ny*w] > ev[sp][cur]+1)
{
ev[sp][nx+ny*w] = ev[sp][cur]+1;
deq.push_back(nx+ny*w);
}
}
}
}
}
void draw(int cur,int id,int &cnt)
{
if(ice[cur] != inf)return;
ice[cur] = id;
cnt++;
rep(i,4)
{
int nx = cur % w + dx[i];
int ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] != 'X')continue;
draw(nx+ny*w,id,cnt);
}
}
void compute()
{
vector<int> initial_array(ice_number+1,0);
initial_array[ice_number] = st[0];
priority_queue<Pox> Q;
Q.push(Pox(initial_array,0));
mincost.insert(initial_array);
int cnt = 0;
while(!Q.empty())
{
Pox pox = Q.top(); Q.pop();
cnt++;
//if(cnt > 10 && !Q.empty() && (cnt%60 == 0 || cnt %120 == 0 || cnt % 73 == 0))Q.pop();
int cost = pox.cost + ev[pox.array[ice_number]][st[1]];
//if(cost >= ev[st[0]][st[1]]*5)continue;
if( cnt % 2 == 0 && !Q.empty())
{
Pox pre = pox;
pox = Q.top(); Q.pop();
Q.push(pre);
}
if(cnt >= 100 && cnt % 3 == 0 && Q.size() >= 2)
{
Pox store = pox;
Pox store2 = Q.top(); Q.pop();
pox = Q.top(); Q.pop();
Q.push(store);
Q.push(store2);
}
/*
if(cnt >= 100 && cnt % 7 == 0 && Q.size() >= 5)
{
Pox store[3];
store[0] = pox;
rep(i,2)
{
store[i+1] = Q.top(); Q.pop();
}
pox = Q.top(); Q.pop();
rep(i,3)Q.push(store[i]);
}
*/
/*
cout << "pox:array:\n";
rep(i,pox.array.size())
cout << "array[" << i << "] = " << pox.array[i] << endl;
cout << "pox:cost:" << pox.cost << endl << endl;
*/
if(st[1] == pox.array[ice_number])
{
cout << pox.cost << endl;
return;
}
rep(i,4)
{
int nx = pox.array[ice_number] % w + dx[i];
int ny = pox.array[ice_number] / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
vector<int> next = pox.array;
next[ice_number] = nx+ny*w;
if(g[ny][nx] == 'X')
{
if(ice_cnt[ice[nx+ny*w]] < 2*(pox.array[ice[nx+ny*w]] + 1))continue;
next[ice[nx+ny*w]]++;
}
if(mincost.find(next) == mincost.end())
{
mincost.insert(next);
Q.push(Pox(next,pox.cost+1));
}
}
}
assert(false);
}
int main()
{
while(scanf("%d %d",&w,&h),w|h)
{
init();
getInput();
//make_ev();
rep(y,h)rep(x,w)
if(g[y][x] == 'X' && ice[x+y*w] == inf)
{
int cnt = 0;
draw(x+y*w,ice_number,cnt);
ice_cnt[ice_number] = cnt;
ice_number++;
}
compute();
}
return 0;
} | a.cc: In function 'void make_ev()':
a.cc:76:7: error: 'ev' was not declared in this scope
76 | ev[sp][sp] = 0;
| ^~
a.cc: In function 'void compute()':
a.cc:130:29: error: 'ev' was not declared in this scope
130 | int cost = pox.cost + ev[pox.array[ice_number]][st[1]];
| ^~
|
s937649721 | p00247 | C++ | #include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<queue>
#include<cassert>
#include<deque>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define all(n) (n).begin(),(n).end()
#define MAX 12
using namespace std;
struct Pox
{
vector<int> array;
int cost;
Pox(vector<int> array=vector<int>(),int cost=inf):array(array),cost(cost){}
bool operator < (const Pox &a)const
{
return cost > a.cost;
}
};
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
//int dx[] = {0,1,0,-1};
//int dy[] = {1,0,-1,0};
//int ev[MAX*MAX][MAX*MAX];//評価値 ev[a][b] := aからbまでの最短コスト
char g[MAX][MAX];
int st[2],h,w,ice_number,T;
int ice[MAX*MAX];
int ice_cnt[MAX*MAX];
set<vector<int> > mincost;
void init()
{
ice_number = 0;
rep(i,h)rep(j,w)ice[j+i*w] = ice_cnt[j+i*w] = inf;
//rep(i,h*w)rep(j,h*w)ev[i][j] = inf;
mincost.clear();
}
void getInput()
{
rep(i,h)
{
getchar();
rep(j,w)
{
scanf("%c",&g[i][j]);
if(g[i][j] == 'S')
{
st[1] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == 'G')
{
st[0] = j + i * w;
g[i][j] = '.';
}
}
}
}
void make_ev()
{
rep(sp,h*w)
{
ev[sp][sp] = 0;
deque<int> deq;
deq.push_back(sp);
while(!deq.empty())
{
int cur = deq.front(); deq.pop_front();
rep(i,4)
{
int nx = cur % w + dx[i];
int ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
if(ev[sp][nx+ny*w] > ev[sp][cur]+1)
{
ev[sp][nx+ny*w] = ev[sp][cur]+1;
deq.push_back(nx+ny*w);
}
}
}
}
}
void draw(int cur,int id,int &cnt)
{
if(ice[cur] != inf)return;
ice[cur] = id;
cnt++;
rep(i,4)
{
int nx = cur % w + dx[i];
int ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] != 'X')continue;
draw(nx+ny*w,id,cnt);
}
}
void compute()
{
vector<int> initial_array(ice_number+1,0);
initial_array[ice_number] = st[0];
priority_queue<Pox> Q;
Q.push(Pox(initial_array,0));
mincost.insert(initial_array);
int cnt = 0;
while(!Q.empty())
{
Pox pox = Q.top(); Q.pop();
cnt++;
//if(cnt > 10 && !Q.empty() && (cnt%60 == 0 || cnt %120 == 0 || cnt % 73 == 0))Q.pop();
int cost = pox.cost + ev[pox.array[ice_number]][st[1]];
//if(cost >= ev[st[0]][st[1]]*5)continue;
if( cnt % 2 == 0 && !Q.empty())
{
Pox pre = pox;
pox = Q.top(); Q.pop();
Q.push(pre);
}
if(cnt >= 100 && cnt % 3 == 0 && Q.size() >= 2)
{
Pox store = pox;
Pox store2 = Q.top(); Q.pop();
pox = Q.top(); Q.pop();
Q.push(store);
Q.push(store2);
}
/*
if(cnt >= 100 && cnt % 7 == 0 && Q.size() >= 5)
{
Pox store[3];
store[0] = pox;
rep(i,2)
{
store[i+1] = Q.top(); Q.pop();
}
pox = Q.top(); Q.pop();
rep(i,3)Q.push(store[i]);
}
*/
/*
cout << "pox:array:\n";
rep(i,pox.array.size())
cout << "array[" << i << "] = " << pox.array[i] << endl;
cout << "pox:cost:" << pox.cost << endl << endl;
*/
if(st[1] == pox.array[ice_number])
{
cout << pox.cost << endl;
return;
}
rep(i,4)
{
int nx = pox.array[ice_number] % w + dx[i];
int ny = pox.array[ice_number] / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
vector<int> next = pox.array;
next[ice_number] = nx+ny*w;
if(g[ny][nx] == 'X')
{
if(ice_cnt[ice[nx+ny*w]] < 2*(pox.array[ice[nx+ny*w]] + 1))continue;
next[ice[nx+ny*w]]++;
}
if(mincost.find(next) == mincost.end())
{
mincost.insert(next);
Q.push(Pox(next,pox.cost+1));
}
}
}
assert(false);
}
int main()
{
while(scanf("%d %d",&w,&h),w|h)
{
init();
getInput();
//make_ev();
rep(y,h)rep(x,w)
if(g[y][x] == 'X' && ice[x+y*w] == inf)
{
int cnt = 0;
draw(x+y*w,ice_number,cnt);
ice_cnt[ice_number] = cnt;
ice_number++;
}
compute();
}
return 0;
} | a.cc: In function 'void make_ev()':
a.cc:76:7: error: 'ev' was not declared in this scope
76 | ev[sp][sp] = 0;
| ^~
a.cc: In function 'void compute()':
a.cc:130:29: error: 'ev' was not declared in this scope
130 | int cost = pox.cost + ev[pox.array[ice_number]][st[1]];
| ^~
|
s873503397 | p00247 | C++ | #include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<queue>
#include<cassert>
#include<deque>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define all(n) (n).begin(),(n).end()
#define MAX 12
using namespace std;
struct Pox
{
vector<int> array;
int cost;
Pox(vector<int> array=vector<int>(),int cost=inf):array(array),cost(cost){}
bool operator < (const Pox &a)const
{
return cost > a.cost;
}
};
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
int max_ans;
//int dx[] = {0,1,0,-1};
//int dy[] = {1,0,-1,0};
int ev[MAX*MAX][MAX*MAX];//評価値 ev[a][b] := aからbまでの最短コスト
char g[MAX][MAX];
int st[2],h,w,ice_number,T;
int ice[MAX*MAX];
int ice_cnt[MAX*MAX];
set<vector<int> > mincost;
//priority_queue<Pox> Q;
//queue<Pox> Q;
deque<Pox> Q;
void init()
{
max_ans = 0;
while(!Q.empty())Q.pop_back();
ice_number = 0;
rep(i,h)rep(j,w)ice[j+i*w] = ice_cnt[j+i*w] = inf;
//rep(i,h*w)rep(j,h*w)ev[i][j] = inf;
mincost.clear();
}
void getInput()
{
rep(i,h)
{
getchar();
rep(j,w)
{
scanf("%c",&g[i][j]);
if(g[i][j] == 'S')
{
st[0] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == 'G')
{
st[1] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == '.')max_ans++;
}
}
}
void make_ev()
{
rep(sp,h*w)
{
ev[sp][sp] = 0;
deque<int> deq;
deq.push_back(sp);
while(!deq.empty())
{
int cur = deq.front(); deq.pop_front();
if(cur == st[1])break;
rep(i,4)
{
int nx = cur % w + dx[i];
int ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
if(ev[sp][nx+ny*w] > ev[sp][cur]+1)
{
ev[sp][nx+ny*w] = ev[sp][cur]+1;
deq.push_back(nx+ny*w);
}
}
}
}
}
void draw(int cur,int id,int &cnt)
{
if(ice[cur] != inf)return;
ice[cur] = id;
cnt++;
rep(i,4)
{
int nx = cur % w + dx[i];
int ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] != 'X')continue;
draw(nx+ny*w,id,cnt);
}
}
bool compute(int depth)
{
int cnt = 0;
while(!Q.empty())
{
Pox pox = Q.front(); Q.pop_front();
cnt++;
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= max_ans)continue;
//if(cnt > 10 && !Q.empty() && (cnt%60 == 0 || cnt %120 == 0 || cnt % 73 == 0))Q.pop();
// int cost = pox.cost + ev[pox.array[ice_number]][st[1]];
//if(cost >= ev[st[0]][st[1]]*5)continue;
if( (cnt % 666 == 0|| cnt % 700 == 0) && !Q.empty())
{
Pox pre = pox;
pox = Q.front(); Q.pop();
//Q.push(pre);
}
/*
if(cnt >= 100 && cnt % 3 == 0 && Q.size() >= 2)
{
Pox store = pox;
Pox store2 = Q.top(); Q.pop();
pox = Q.top(); Q.pop();
Q.push(store);
Q.push(store2);
}
*/
/*
if(cnt >= 100 && cnt % 7 == 0 && Q.size() >= 5)
{
Pox store[3];
store[0] = pox;
rep(i,2)
{
store[i+1] = Q.top(); Q.pop();
}
pox = Q.top(); Q.pop();
rep(i,3)Q.push(store[i]);
}
*/
/*
cout << "pox:array:\n";
rep(i,pox.array.size())
cout << "array[" << i << "] = " << pox.array[i] << endl;
cout << "pox:cost:" << pox.cost << endl << endl;
*/
if(st[1] == pox.array[ice_number])
{
cout << pox.cost << endl;
return true;
}
if(pox.cost >= depth)
{
Q.push_back(pox);
return false;
}
rep(i,4)
{
int nx = pox.array[ice_number] % w + dx[i];
int ny = pox.array[ice_number] / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
vector<int> next = pox.array;
next[ice_number] = nx+ny*w;
if(g[ny][nx] == 'X')
{
if(ice_cnt[ice[nx+ny*w]] < 2*(pox.array[ice[nx+ny*w]] + 1))continue;
next[ice[nx+ny*w]]++;
}
if(mincost.find(next) == mincost.end())
{
mincost.insert(next);
if(Q.front().cost > pox.cost+1)
Q.push_front(Pox(next,pox.cost+1));
else
Q.push_back(Pox(next,pox.cost+1));
}
}
}
return false;
}
int main()
{
while(scanf("%d %d",&w,&h),w|h)
{
init();
getInput();
make_ev();
rep(y,h)rep(x,w)
if(g[y][x] == 'X' && ice[x+y*w] == inf)
{
int cnt = 0;
draw(x+y*w,ice_number,cnt);
ice_cnt[ice_number] = cnt;
ice_number++;
}
rep(i,ice_number)max_ans += ice_cnt[i];
vector<int> initial_array(ice_number+1,0);
initial_array[ice_number] = st[0];
Q.push_back(Pox(initial_array,0));
mincost.insert(initial_array);
int depth = 0;
while(!compute(depth++));
}
return 0;
} | a.cc: In function 'bool compute(int)':
a.cc:140:30: error: 'class std::deque<Pox>' has no member named 'pop'
140 | pox = Q.front(); Q.pop();
| ^~~
|
s038956667 | p00247 | C++ | #include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<queue>
#include<cassert>
#include<deque>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define all(n) (n).begin(),(n).end()
#define MAX 12
#define sinf (30000)
#define cinf (254)
using namespace std;
typedef unsigned short us;
typedef unsigned char uc;
struct Pox
{
vector<uc> array;
us cost;
us prev;
Pox(vector<uc> array=vector<uc>(),us cost=sinf,us prev=sinf):array(array),cost(cost),prev(prev){}
};
uc dx[] = {1,0,-1,0};
uc dy[] = {0,-1,0,1};
us max_ans;
//int dx[] = {0,1,0,-1};
//int dy[] = {1,0,-1,0};
uc ev[MAX*MAX][MAX*MAX];//評価値 ev[a][b] := aからbまでの最短コスト
char g[MAX][MAX];
us st[2],h,w,ice_number;
int ice[MAX*MAX];
int ice_cnt[MAX*MAX];
set<vector<uc> > mincost;
//set<ull> mincost;
//priority_queue<Pox> Q;
//queue<Pox> Q;
deque<Pox> Q;
void init()
{
max_ans = 0;
// while(!Q.empty())Q.pop_back();
ice_number = 0;
rep(i,h)rep(j,w)ice[j+i*w] = ice_cnt[j+i*w] = inf;
//rep(i,h*w)rep(j,h*w)ev[i][j] = inf;
mincost.clear();
}
void getInput()
{
rep(i,h)
{
getchar();
rep(j,w)
{
scanf("%c",&g[i][j]);
if(g[i][j] == 'S')
{
st[0] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == 'G')
{
st[1] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == '.')max_ans++;
}
}
}
void make_ev()
{
rep(sp,h*w)
{
ev[sp][sp] = 0;
deque<us> deq;
deq.push_back(sp);
while(!deq.empty())
{
int cur = deq.front(); deq.pop_front();
if(cur == st[1])break;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
if(ev[sp][nx+ny*w] > ev[sp][cur]+1)
{
ev[sp][nx+ny*w] = ev[sp][cur]+1;
deq.push_back(nx+ny*w);
}
}
}
}
}
void draw(uc cur,uc id,int &cnt)
{
if(ice[cur] != inf)return;
ice[cur] = id;
cnt++;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] != 'X')continue;
draw(nx+ny*w,id,cnt);
}
}
bool compute(us depth)
{
while(!Q.empty())
{
Pox pox = Q.front(); Q.pop_front();
//cnt++;
//if(pox.cost + ev[pox.array[ice_number]][st[1]] >= max_ans)continue;
//if(cnt > 10 && !Q.empty() && (cnt%60 == 0 || cnt %120 == 0 || cnt % 73 == 0))Q.pop();
// int cost = pox.cost + ev[pox.array[ice_number]][st[1]];
//if(cost >= ev[st[0]][st[1]]*5)continue;
/*
if( (cnt % 666 == 0|| cnt % 700 == 0) && !Q.empty())
{
Pox pre = pox;
pox = Q.front(); Q.pop_front();
continue;
//Q.push(pre);
}
*/
/*
if(cnt >= 100 && cnt % 3 == 0 && Q.size() >= 2)
{
Pox store = pox;
Pox store2 = Q.top(); Q.pop();
pox = Q.top(); Q.pop();
Q.push(store);
Q.push(store2);
}
*/
/*
if(cnt >= 100 && cnt % 7 == 0 && Q.size() >= 5)
{
Pox store[3];
store[0] = pox;
rep(i,2)
{
store[i+1] = Q.top(); Q.pop();
}
pox = Q.top(); Q.pop();
rep(i,3)Q.push(store[i]);
}
*/
/*
cout << "pox:array:\n";
rep(i,pox.array.size())
cout << "array[" << i << "] = " << pox.array[i] << endl;
cout << "pox:cost:" << pox.cost << endl << endl;
*/
if(st[1] == pox.array[ice_number])
{
//printf("h\n",pox.cost);
cout << pox.cost << endl;
return true;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= max_ans)
{
continue;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= depth)
{
Q.push_back(pox);
return false;
}
rep(i,4)
{
if(pox.prev != -1 && pox.prev == (i+2)%4)continue;
uc nx = pox.array[ice_number] % w + dx[i];
uc ny = pox.array[ice_number] / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
vector<uc> next = pox.array;
next[ice_number] = nx+ny*w;
if(g[ny][nx] == 'X')
{
if(ice_cnt[ice[nx+ny*w]] < 2*(pox.array[ice[nx+ny*w]] + 1))continue;
next[ice[nx+ny*w]]++;
}
if(mincost.find(next) == mincost.end())
{
mincost.insert(next);
if(Q.front().cost > pox.cost+1)
Q.push_front(Pox(next,pox.cost+1,i));
else
Q.push_back(Pox(next,pox.cost+1,i));
}
}
}
return false;
}
int main()
{
//while(scanf("h h",&w,&h),w|h)
while(cin >> w >> h,w|h)
{
init();
getInput();
make_ev();
rep(y,h)rep(x,w)
if(g[y][x] == 'X' && ice[x+y*w] == inf)
{
int cnt = 0;
draw(x+y*w,ice_number,cnt);
ice_cnt[ice_number] = cnt;
ice_number++;
}
rep(i,ice_number)max_ans += ice_cnt[i];
vector<uc> initial_array(ice_number+1,0);
initial_array[ice_number] = st[0];
Q.push_back(Pox(initial_array,0,-1));
mincost.insert(initial_array);
us depth = 0;
while(!compute(depth++));
while(!Q.empty())Q.pop_back();
}
return 0;
} | a.cc:33:16: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
33 | uc dx[] = {1,0,-1,0};
| ^~
a.cc:34:14: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
34 | uc dy[] = {0,-1,0,1};
| ^~
|
s293291662 | p00247 | C++ | #include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<queue>
#include<cassert>
#include<deque>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define all(n) (n).begin(),(n).end()
#define MAX 12
#define sinf (30000)
#define cinf (254)
using namespace std;
typedef unsigned short us;
typedef unsigned char uc;
struct Pox
{
vector<uc> array;
us cost;
us prev;
Pox(vector<uc> array=vector<uc>(),us cost=sinf,us prev=sinf):array(array),cost(cost),prev(prev){}
};
uc dx[] = {1,0,-1,0};
uc dy[] = {0,-1,0,1};
us max_ans;
uc ev[MAX*MAX][MAX*MAX];//評価値 ev[a][b] := aからbまでの最短コスト
char g[MAX][MAX];
us st[2],h,w,ice_number;
int ice[MAX*MAX];
int ice_cnt[MAX*MAX];
set<vector<uc> > mincost;
deque<Pox> Q;
void init()
{
max_ans = 0;
ice_number = 0;
rep(i,h)rep(j,w)ice[j+i*w] = ice_cnt[j+i*w] = inf;
}
void getInput()
{
rep(i,h)
{
getchar();
rep(j,w)
{
scanf("%c",&g[i][j]);
if(g[i][j] == 'S')
{
st[0] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == 'G')
{
st[1] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == '.')max_ans++;
}
}
}
void make_ev()
{
rep(sp,h*w)
{
ev[sp][sp] = 0;
deque<us> deq;
deq.push_back(sp);
while(!deq.empty())
{
int cur = deq.front(); deq.pop_front();
if(cur == st[1])break;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
if(ev[sp][nx+ny*w] > ev[sp][cur]+1)
{
ev[sp][nx+ny*w] = ev[sp][cur]+1;
deq.push_back(nx+ny*w);
}
}
}
}
}
void draw(uc cur,uc id,int &cnt)
{
if(ice[cur] != inf)return;
ice[cur] = id;
cnt++;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] != 'X')continue;
draw(nx+ny*w,id,cnt);
}
}
bool compute(us depth)
{
while(!Q.empty())
{
Pox pox = Q.front(); Q.pop_front();
if(st[1] == pox.array[ice_number])
{
cout << pox.cost << endl;
return true;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= max_ans)
{
continue;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= depth)
{
Q.push_back(pox);
return false;
}
rep(i,4)
{
if(pox.prev != -1 && pox.prev == (i+2)%4)continue;
uc nx = pox.array[ice_number] % w + dx[i];
uc ny = pox.array[ice_number] / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
vector<uc> next = pox.array;
next[ice_number] = nx+ny*w;
if(g[ny][nx] == 'X')
{
if(ice_cnt[ice[nx+ny*w]] < 2*(pox.array[ice[nx+ny*w]] + 1))continue;
next[ice[nx+ny*w]]++;
}
if(mincost.find(next) == mincost.end())
{
mincost.insert(next);
if(Q.front().cost > pox.cost+1)
Q.push_front(Pox(next,pox.cost+1,i));
else
Q.push_back(Pox(next,pox.cost+1,i));
}
}
}
return false;
}
int main()
{
while(cin >> w >> h,w|h)
{
init();
getInput();
make_ev();
rep(y,h)rep(x,w)
if(g[y][x] == 'X' && ice[x+y*w] == inf)
{
int cnt = 0;
draw(x+y*w,ice_number,cnt);
ice_cnt[ice_number] = cnt;
ice_number++;
}
rep(i,ice_number)max_ans += ice_cnt[i]/2;
vector<uc> initial_array(ice_number+1,0);
initial_array[ice_number] = st[0];
Q.push_back(Pox(initial_array,0,-1));
mincost.insert(initial_array);
us depth = 0;
while(!compute(depth++));
while(!Q.empty())Q.pop_back();
mincost.clear();
}
return 0;
} | a.cc:33:16: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
33 | uc dx[] = {1,0,-1,0};
| ^~
a.cc:34:14: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
34 | uc dy[] = {0,-1,0,1};
| ^~
|
s761639567 | p00247 | C++ | #include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<queue>
#include<cassert>
#include<deque>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define all(n) (n).begin(),(n).end()
#define MAX 12
#define sinf (30000)
#define cinf (254)
using namespace std;
typedef unsigned short us;
typedef unsigned char uc;
struct Pox
{
vector<uc> array;
uc cost;
uc prev;
Pox(vector<uc> array=vector<uc>(),uc cost=cinf,uc prev=cinf):array(array),cost(cost),prev(prev){}
};
uc dx[] = {1,0,-1,0};
uc dy[] = {0,-1,0,1};
uc max_ans;
uc ev[MAX*MAX][MAX*MAX];//評価値 ev[a][b] := aからbまでの最短コスト
char g[MAX][MAX];
us st[2],h,w,ice_number;
int ice[MAX*MAX];
int ice_cnt[MAX*MAX];
set<vector<uc> > mincost;
deque<Pox> Q;
void init()
{
max_ans = 0;
ice_number = 0;
rep(i,h)rep(j,w)ice[j+i*w] = ice_cnt[j+i*w] = inf;
}
void getInput()
{
rep(i,h)
{
getchar();
rep(j,w)
{
scanf("%c",&g[i][j]);
if(g[i][j] == 'S')
{
st[0] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == 'G')
{
st[1] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == '.')max_ans++;
}
}
}
void make_ev()
{
rep(sp,h*w)
{
ev[sp][sp] = 0;
deque<us> deq;
deq.push_back(sp);
while(!deq.empty())
{
int cur = deq.front(); deq.pop_front();
if(cur == st[1])break;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
if(ev[sp][nx+ny*w] > ev[sp][cur]+1)
{
ev[sp][nx+ny*w] = ev[sp][cur]+1;
deq.push_back(nx+ny*w);
}
}
}
}
}
void draw(uc cur,uc id,int &cnt)
{
if(ice[cur] != inf)return;
ice[cur] = id;
cnt++;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] != 'X')continue;
draw(nx+ny*w,id,cnt);
}
}
bool compute(us depth)
{
while(!Q.empty())
{
Pox pox = Q.front(); Q.pop_front();
if(st[1] == pox.array[ice_number])
{
cout << (short)pox.cost << endl;
return true;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= max_ans)
{
continue;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= depth)
{
Q.push_back(pox);
return false;
}
rep(i,4)
{
if(pox.prev != -1 && pox.prev == (i+2)%4)continue;
uc nx = pox.array[ice_number] % w + dx[i];
uc ny = pox.array[ice_number] / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
vector<uc> next = pox.array;
next[ice_number] = nx+ny*w;
if(g[ny][nx] == 'X')
{
if(ice_cnt[ice[nx+ny*w]] < 2*(pox.array[ice[nx+ny*w]] + 1))continue;
next[ice[nx+ny*w]]++;
}
if(mincost.find(next) == mincost.end())
{
mincost.insert(next);
if(Q.front().cost > pox.cost+1)
Q.push_front(Pox(next,pox.cost+1,i));
else
Q.push_back(Pox(next,pox.cost+1,i));
}
}
}
return false;
}
int main()
{
while(cin >> w >> h,w|h)
{
init();
getInput();
make_ev();
rep(y,h)rep(x,w)
if(g[y][x] == 'X' && ice[x+y*w] == inf)
{
int cnt = 0;
draw(x+y*w,ice_number,cnt);
ice_cnt[ice_number] = cnt;
ice_number++;
}
rep(i,ice_number)max_ans += ice_cnt[i]/2;
vector<uc> initial_array(ice_number+1,0);
initial_array[ice_number] = st[0];
Q.push_back(Pox(initial_array,0,-1));
mincost.insert(initial_array);
us depth = 0;
while(!compute(depth++));
while(!Q.empty())Q.pop_back();
mincost.clear();
}
return 0;
} | a.cc:33:16: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
33 | uc dx[] = {1,0,-1,0};
| ^~
a.cc:34:14: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
34 | uc dy[] = {0,-1,0,1};
| ^~
|
s211856142 | p00247 | C++ | #include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<queue>
#include<cassert>
#include<deque>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define all(n) (n).begin(),(n).end()
#define MAX 12
#define sinf (30000)
#define cinf (254)
using namespace std;
typedef unsigned short us;
typedef unsigned char uc;
struct Pox
{
vector<uc> array;
us cost;
us prev;
Pox(vector<uc> array=vector<uc>(),us cost=cinf,us prev=cinf):array(array),cost(cost),prev(prev){}
};
uc dx[] = {1,0,-1,0};
uc dy[] = {0,-1,0,1};
uc max_ans;
uc ev[MAX*MAX][MAX*MAX];//評価値 ev[a][b] := aからbまでの最短コスト
char g[MAX][MAX];
us st[2],h,w,ice_number;
int ice[MAX*MAX];
uc ice_cnt[MAX*MAX];
set<vector<uc> > mincost;
deque<Pox> Q;
void init()
{
max_ans = 0;
ice_number = 0;
rep(i,h)rep(j,w)
{
ice[j+i*w] = inf;
ice_cnt[j+i*w] = cinf;
}
}
void getInput()
{
rep(i,h)
{
getchar();
rep(j,w)
{
scanf("%c",&g[i][j]);
if(g[i][j] == 'S')
{
st[0] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == 'G')
{
st[1] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == '.')max_ans++;
}
}
}
void make_ev()
{
rep(sp,h*w)
{
ev[sp][sp] = 0;
deque<us> deq;
deq.push_back(sp);
while(!deq.empty())
{
int cur = deq.front(); deq.pop_front();
if(cur == st[1])break;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
if(ev[sp][nx+ny*w] > ev[sp][cur]+1)
{
ev[sp][nx+ny*w] = ev[sp][cur]+1;
deq.push_back(nx+ny*w);
}
}
}
}
}
void draw(uc cur,uc id,int &cnt)
{
if(ice[cur] != inf)return;
ice[cur] = id;
cnt++;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] != 'X')continue;
draw(nx+ny*w,id,cnt);
}
}
bool compute(us depth)
{
while(!Q.empty())
{
Pox pox = Q.front(); Q.pop_front();
if(st[1] == pox.array[ice_number])
{
cout << pox.cost << endl;
return true;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= max_ans)
{
continue;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= depth)
{
Q.push_back(pox);
return false;
}
rep(i,4)
{
if(pox.prev != -1 && pox.prev == (i+2)%4)continue;
uc nx = pox.array[ice_number] % w + dx[i];
uc ny = pox.array[ice_number] / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
vector<uc> next = pox.array;
next[ice_number] = nx+ny*w;
if(g[ny][nx] == 'X')
{
if(ice_cnt[ice[nx+ny*w]] < 2*(pox.array[ice[nx+ny*w]] + 1))continue;
next[ice[nx+ny*w]]++;
}
if(mincost.find(next) == mincost.end())
{
mincost.insert(next);
if(Q.front().cost > pox.cost+1)
Q.push_front(Pox(next,pox.cost+1,i));
else
Q.push_back(Pox(next,pox.cost+1,i));
}
}
}
return false;
}
int main()
{
while(cin >> w >> h,w|h)
{
init();
getInput();
make_ev();
rep(y,h)rep(x,w)
if(g[y][x] == 'X' && ice[x+y*w] == inf)
{
int cnt = 0;
draw(x+y*w,ice_number,cnt);
ice_cnt[ice_number] = cnt;
ice_number++;
}
rep(i,ice_number)max_ans += ice_cnt[i]/2;
vector<uc> initial_array(ice_number+1,0);
initial_array[ice_number] = st[0];
Q.push_back(Pox(initial_array,0,-1));
mincost.insert(initial_array);
us depth = 0;
while(!compute(depth++));
while(!Q.empty())Q.pop_back();
mincost.clear();
}
return 0;
} | a.cc:33:16: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
33 | uc dx[] = {1,0,-1,0};
| ^~
a.cc:34:14: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
34 | uc dy[] = {0,-1,0,1};
| ^~
|
s503018650 | p00247 | C++ | #include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<queue>
#include<cassert>
#include<deque>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define all(n) (n).begin(),(n).end()
#define MAX 12
#define sinf (30000)
#define cinf (254)
using namespace std;
typedef unsigned short us;
typedef unsigned char uc;
struct Pox
{
vector<uc> array;
us cost;
us prev;
Pox(vector<uc> array=vector<uc>(),us cost=cinf,us prev=cinf):array(array),cost(cost),prev(prev){}
};
uc dx[] = {1,0,-1,0};
uc dy[] = {0,-1,0,1};
uc max_ans;
uc ev[MAX*MAX][MAX*MAX];//評価値 ev[a][b] := aからbまでの最短コスト
char g[MAX][MAX];
us st[2],h,w,ice_number;
int ice[MAX*MAX];
uc ice_cnt[MAX*MAX];
set<vector<uc> > mincost;
deque<Pox> Q;
void init()
{
max_ans = 0;
ice_number = 0;
rep(i,h)rep(j,w)
{
ice[j+i*w] = inf;
ice_cnt[j+i*w] = cinf;
}
}
void getInput()
{
rep(i,h)
{
getchar();
rep(j,w)
{
scanf("%c",&g[i][j]);
if(g[i][j] == 'S')
{
st[0] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == 'G')
{
st[1] = j + i * w;
g[i][j] = '.';
}
if(g[i][j] == '.')max_ans++;
}
}
}
void make_ev()
{
rep(sp,h*w)
{
ev[sp][sp] = 0;
deque<us> deq;
deq.push_back(sp);
while(!deq.empty())
{
uc cur = deq.front(); deq.pop_front();
if(cur == st[1])break;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
if(ev[sp][nx+ny*w] > ev[sp][cur]+1)
{
ev[sp][nx+ny*w] = ev[sp][cur]+1;
deq.push_back(nx+ny*w);
}
}
}
}
}
void draw(uc cur,uc id,int &cnt)
{
if(ice[cur] != inf)return;
ice[cur] = id;
cnt++;
rep(i,4)
{
uc nx = cur % w + dx[i];
uc ny = cur / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] != 'X')continue;
draw(nx+ny*w,id,cnt);
}
}
bool compute(us depth)
{
while(!Q.empty())
{
Pox pox = Q.front(); Q.pop_front();
if(st[1] == pox.array[ice_number])
{
cout << pox.cost << endl;
return true;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= max_ans)
{
continue;
}
if(pox.cost + ev[pox.array[ice_number]][st[1]] >= depth)
{
Q.push_back(pox);
return false;
}
rep(i,4)
{
if(pox.prev != -1 && pox.prev == (i+2)%4)continue;
uc nx = pox.array[ice_number] % w + dx[i];
uc ny = pox.array[ice_number] / w + dy[i];
if(!(0 <= nx && nx < w && 0 <= ny && ny < h))continue;
if(g[ny][nx] == '#')continue;
vector<uc> next = pox.array;
next[ice_number] = nx+ny*w;
if(g[ny][nx] == 'X')
{
if(ice_cnt[ice[nx+ny*w]] < 2*(pox.array[ice[nx+ny*w]] + 1))continue;
next[ice[nx+ny*w]]++;
}
if(mincost.find(next) == mincost.end())
{
mincost.insert(next);
if(Q.front().cost > pox.cost+1)
Q.push_front(Pox(next,pox.cost+1,i));
else
Q.push_back(Pox(next,pox.cost+1,i));
}
}
}
return false;
}
int main()
{
while(cin >> w >> h,w|h)
{
init();
getInput();
make_ev();
rep(y,h)rep(x,w)
if(g[y][x] == 'X' && ice[x+y*w] == inf)
{
int cnt = 0;
draw(x+y*w,ice_number,cnt);
ice_cnt[ice_number] = cnt;
ice_number++;
}
rep(i,ice_number)max_ans += ice_cnt[i]/2;
vector<uc> initial_array(ice_number+1,0);
initial_array[ice_number] = st[0];
Q.push_back(Pox(initial_array,0,-1));
mincost.insert(initial_array);
us depth = 0;
while(!compute(depth++))
{
mincost.clear();
}
while(!Q.empty())Q.pop_back();
mincost.clear();
}
return 0;
} | a.cc:33:16: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
33 | uc dx[] = {1,0,-1,0};
| ^~
a.cc:34:14: error: narrowing conversion of '-1' from 'int' to 'uc' {aka 'unsigned char'} [-Wnarrowing]
34 | uc dy[] = {0,-1,0,1};
| ^~
|
s377373440 | p00250 | C | #include<stdio.h>
int a(int n,int m,int k[30000]){
int i,j,sum,max;
for(i=0;i<n;i++){
sum=0;
for(j=i;j<n;j++){
if(k[j]==0) continue;
if(max==m-1) break;
sum+=k[j];
sum%=m;
if(max<sum) max=sum;
}
if(max==m-1) break;
}
return max;
}
int main()
{
int n,m,i,j;
int k[30000];
while(scanf("%d%d",&n,&m),n+m){
max=0;
for(i=0;i<n;i++){
scanf("%d",&k[i]);
k[i]%=m;
}
printf("%d\n",a(n,m,k));
}
return 0;
} | main.c: In function 'main':
main.c:29:9: error: 'max' undeclared (first use in this function)
29 | max=0;
| ^~~
main.c:29:9: note: each undeclared identifier is reported only once for each function it appears in
|
s244767809 | p00250 | C | #include<stdio.h>
int a(int n,int m,int k[30000]){
int i,j,sum,max=0;
for(i=n-1;i>=0;i--){
sum=0;
for(j=i;j>=0;j--){
if(k[j]==0) continue;
if(max==m-1) break;
sum+=k[j];
sum%=m;
if(max<sum) max=sum;
}
if(max==m-1) break;
}
return max;
}
int main()
{
int n,m,i,j;
int k[30000];
while(scanf("%d%d",&n,&m),n+m){
for(i=0;i<n;i++){
scanf("%d",&k[i]);
k[i]%=m;
sum+=k[i];
sum%=m;
if(sum==m-1) n=-1;
}
if(n==-1){
printf("%d\n",sum);
continue;
}
printf("%d\n",a(n,m,k));
}
return 0;
} | main.c: In function 'main':
main.c:32:1: error: 'sum' undeclared (first use in this function)
32 | sum+=k[i];
| ^~~
main.c:32:1: note: each undeclared identifier is reported only once for each function it appears in
|
s517546579 | p00250 | C++ | #include<stdio.h>
int a(int n,int m,int k[30000]){
int i,j,sum,max;
for(i=0;i<n;i++){
sum=0;
for(j=i;j<n;j++){
if(k[j]==0) continue;
if(max==m-1) break;
sum+=k[j];
sum%=m;
if(max<sum) max=sum;
}
if(max==m-1) break;
}
return max;
}
int main()
{
int n,m,i,j;
int k[30000];
while(scanf("%d%d",&n,&m),n+m){
max=0;
for(i=0;i<n;i++){
scanf("%d",&k[i]);
k[i]%=m;
}
printf("%d\n",a(n,m,k));
}
return 0;
} | a.cc: In function 'int main()':
a.cc:29:9: error: 'max' was not declared in this scope
29 | max=0;
| ^~~
|
s249455697 | p00250 | C++ | #include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
typedef long long ll;
int const inf = 1<<29;
int main() {
for(int N, M; ~scanf("%d%d", &N, &M) && N;) {
int sum[N + 1]; sum[0] = 0;
int res = 0;
rep(i, N) {
int A; scanf("%d", &A); A %= M;
sum[i + 1] = sum[i] + A;
sum[i + 1] %= M;
maximize(res, sum[i + 1]);
}
set<int> st = {M};
REP(i, 1, N + 1) {
maximize(res, sum[i] + M - *st.upper_bound(sum[i]));
st.insert(sum[i]);
}
cout << res << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:22:7: error: 'maximize' was not declared in this scope
22 | maximize(res, sum[i + 1]);
| ^~~~~~~~
a.cc:28:7: error: 'maximize' was not declared in this scope
28 | maximize(res, sum[i] + M - *st.upper_bound(sum[i]));
| ^~~~~~~~
|
s359015837 | p00251 | Java | import java.util.*;
class Main{
private void compute(){
Scanner sc = new Scanner(System.in);
int sum = 0;
for( int i = 0; i < 10; i++){
int x = sc.nextInt();
sum += x;
}
System.out.println(sum);
}
}
public static void main(String args[]){
new Main().compute();
}
} | Main.java:14: error: unnamed classes are a preview feature and are disabled by default.
public static void main(String args[]){
^
(use --enable-preview to enable unnamed classes)
Main.java:18: error: class, interface, enum, or record expected
}
^
2 errors
|
s200106481 | p00251 | Java | 4
4
8
8
8
10
10
12
16
20 | Main.java:1: error: class, interface, enum, or record expected
4
^
1 error
|
s648253092 | p00251 | Java | package hoge.hoge.com;
import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args)
throws java.io.IOException{
// TODO 自動生成されたメソッド・スタブ
Scanner scan = new Scanner(System.in);
int i=0,a;
for(a=0;a<10;a++){
String str = scan.next();
i += Integer.parseInt(str);
}
System.out.println(+i\n);
}
} | Main.java:21: error: illegal character: '\'
System.out.println(+i\n);
^
Main.java:21: error: not a statement
System.out.println(+i\n);
^
Main.java:21: error: ';' expected
System.out.println(+i\n);
^
3 errors
|
s067131008 | p00251 | Java | package hoge.hoge.com;
import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args)
throws java.io.IOException{
// TODO 自動生成されたメソッド・スタブ
Scanner scan = new Scanner(System.in);
int i=0,a;
for(a=0;a<10;a++){
String str = scan.next();
i += Integer.parseInt(str);
}
System.out.println(+i);
}
} | Main.java:5: error: class HelloWorld is public, should be declared in a file named HelloWorld.java
public class HelloWorld {
^
1 error
|
s855194191 | p00251 | Java |
public class HelloWorld {
public static void main (String[] args) {
System.out.println("Hello World !!");
int i=0,a;
Scanner scan = new Scanner(System.in);
for(a=0;a<10;a++){
String str = scan.next();
i += Integer.parseInt(str);
}
System.out.printfln(+i);
}
} | Main.java:2: error: class HelloWorld is public, should be declared in a file named HelloWorld.java
public class HelloWorld {
^
Main.java:6: error: cannot find symbol
Scanner scan = new Scanner(System.in);
^
symbol: class Scanner
location: class HelloWorld
Main.java:6: error: cannot find symbol
Scanner scan = new Scanner(System.in);
^
symbol: class Scanner
location: class HelloWorld
Main.java:11: error: cannot find symbol
System.out.printfln(+i);
^
symbol: method printfln(int)
location: variable out of type PrintStream
4 errors
|
s144652955 | p00251 | Java | public class sample{
public static void main(String[] args){
int i,a,g=0;
for(i=0;i<10;i++){
a=System.in.read();
g+=a;
}
System.out.println(g);
}
} | Main.java:1: error: class sample is public, should be declared in a file named sample.java
public class sample{
^
1 error
|
s018268042 | p00251 | Java | import java.io.*;
public class sample {
public static void main(String[] args){
try{
int a,b,c=0;
for(a=0;a<10;a++){
b=System.in.read();
c+=b;
}
System.out.println(c);
}catch(IOException e){}
}
} | Main.java:2: error: class sample is public, should be declared in a file named sample.java
public class sample {
^
1 error
|
s566569135 | p00251 | Java | import java.util.Scanner;
class exe0256
{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
sum=0;
for(int i=0;i<10;i++)
{
int s=scan.nextInt();
sum+=s;
}
System.out.println(sum);
}
} | Main.java:7: error: cannot find symbol
sum=0;
^
symbol: variable sum
location: class exe0256
Main.java:11: error: cannot find symbol
sum+=s;
^
symbol: variable sum
location: class exe0256
Main.java:13: error: cannot find symbol
System.out.println(sum);
^
symbol: variable sum
location: class exe0256
3 errors
|
s484572928 | p00251 | Java | import java.util.Scanner;
public class aoj0256 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int count = 0;
for(int i = 0;i < 10;i++){
int n = in.nextInt();
count = count + n;
}
System.out.println(count);
}
} | Main.java:3: error: class aoj0256 is public, should be declared in a file named aoj0256.java
public class aoj0256 {
^
1 error
|
s685706439 | p00251 | C | import java.util.Scanner;
public class J0256{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int sum=0;
for(int i=0; i<10; i++){
int n = sc.nextInt();
sum += n;
}
System.out.println(sum);
}
} | main.c:1:1: error: unknown type name 'import'
1 | import java.util.Scanner;
| ^~~~~~
main.c:1:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
1 | import java.util.Scanner;
| ^
main.c:3:1: error: unknown type name 'public'
3 | public class J0256{
| ^~~~~~
main.c:3:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'J0256'
3 | public class J0256{
| ^~~~~
|
s395068669 | p00251 | C | #include<stdio.h>
int main(){
int string[10];
int i;
int ans=0;
for(i=0;i<=9i++){
scanf("%d", &string[i]);
ans+=string[i];
}
printf("%d\n",ans);
return 0;
} | main.c: In function 'main':
main.c:6:18: error: lvalue required as increment operand
6 | for(i=0;i<=9i++){
| ^~
main.c:6:20: error: expected ';' before ')' token
6 | for(i=0;i<=9i++){
| ^
| ;
|
s856027520 | p00251 | C | #include<stdio.h>
int main(){
int a[10];
int i;
int ans=0;
for(i=0;i<=9i++){
scanf("%d", &a[i]);
ans+=a[i];
}
printf("%d\n", ans);
return 0;
} | main.c: In function 'main':
main.c:7:18: error: lvalue required as increment operand
7 | for(i=0;i<=9i++){
| ^~
main.c:7:20: error: expected ';' before ')' token
7 | for(i=0;i<=9i++){
| ^
| ;
|
s032505330 | p00251 | C | #include <stdio.h>
int main(){
int i,a[10],sum=0;
for(i=0;i<10;i++){
scanf("%d",&a[i]);
sum+=a[i]
}
printf("%d",sum);
return 0;
} | main.c: In function 'main':
main.c:7:12: error: expected ';' before '}' token
7 | sum+=a[i]
| ^
| ;
8 | }
| ~
|
s130603746 | p00251 | C | #include<stdio.h>
int main(void)
{
int a,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10;
scanf("%d %d %d %d %d %d %d %d %d %d"&s1,&s2,&s3,&s4,&s5,&s6,&s7,&s8,&s9,&s10);
a=s1+s2+s3+s4+s5+s6+s7+s8+s9+10;
printf("%d\n",a);
return 0;
} | main.c: In function 'main':
main.c:5:38: error: invalid operands to binary & (have 'char *' and 'int')
5 | scanf("%d %d %d %d %d %d %d %d %d %d"&s1,&s2,&s3,&s4,&s5,&s6,&s7,&s8,&s9,&s10);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
| |
| char *
|
s795709840 | p00251 | C | #include<stdio.h>
int main(void)
{
int s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,a;
scanf("%d %d %d %d %d %d %d %d %d %d"&s1,&s2,&s3,&s4,&s5,&s6,&s7,&s8,&s9,&s10);
a=s1+s2+s3+s4+s5+s6+s7+s8+s9+10;
printf("%d\n",a);
return 0;
} | main.c: In function 'main':
main.c:5:38: error: invalid operands to binary & (have 'char *' and 'int')
5 | scanf("%d %d %d %d %d %d %d %d %d %d"&s1,&s2,&s3,&s4,&s5,&s6,&s7,&s8,&s9,&s10);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
| |
| char *
|
s449564507 | p00251 | C | #include<stdio.h>
int main()
{
int s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,a;
scanf("%d %d %d %d %d %d %d %d %d %d"&s1,&s2,&s3,&s4,&s5,&s6,&s7,&s8,&s9,&s10);
a=s1+s2+s3+s4+s5+s6+s7+s8+s9+10;
printf("%d\n",a);
return 0;
} | main.c: In function 'main':
main.c:5:38: error: invalid operands to binary & (have 'char *' and 'int')
5 | scanf("%d %d %d %d %d %d %d %d %d %d"&s1,&s2,&s3,&s4,&s5,&s6,&s7,&s8,&s9,&s10);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
| |
| char *
|
s510222452 | p00251 | C | #include<iostream>
using namespace std;
int main(){
int ans=0;
int tmp;
for(int i=0;i<10;i++){
cin>>tmp;
ans+=tmp;
}
cout<<ans<<endl;
} | main.c:1:9: fatal error: iostream: No such file or directory
1 | #include<iostream>
| ^~~~~~~~~~
compilation terminated.
|
s153653666 | p00251 | C | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);} | main.c:1:1: warning: data definition has no type or storage class
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 's' [-Wimplicit-int]
main.c:1:3: error: return type defaults to 'int' [-Wimplicit-int]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
| ^~~~
main.c: In function 'main':
main.c:1:3: error: type of 'x' defaults to 'int' [-Wimplicit-int]
main.c:1:12: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
main.c:1:12: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
| ^~~~~
main.c:1:12: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:38: error: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
| ^~~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
+++ |+#include <stdlib.h>
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
main.c:1:38: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
| ^~~~
main.c:1:38: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c:1:44: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
| ^~~~~~
main.c:1:44: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:44: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:1:44: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:60: error: expected ')' before ';' token
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
| ~ ^
| )
main.c:1:61: error: expected ';' before '}' token
1 | s;main(x){~scanf("%d",&x)?main(s+=x):exit(!printf("%d\n",s);}
| ^
| ;
|
s454226021 | p00251 | C | s;main(x){~scanf("%d",&x)?main(s+=x):x=!printf("%d\n",s);} | main.c:1:1: warning: data definition has no type or storage class
1 | s;main(x){~scanf("%d",&x)?main(s+=x):x=!printf("%d\n",s);}
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 's' [-Wimplicit-int]
main.c:1:3: error: return type defaults to 'int' [-Wimplicit-int]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):x=!printf("%d\n",s);}
| ^~~~
main.c: In function 'main':
main.c:1:3: error: type of 'x' defaults to 'int' [-Wimplicit-int]
main.c:1:12: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):x=!printf("%d\n",s);}
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | s;main(x){~scanf("%d",&x)?main(s+=x):x=!printf("%d\n",s);}
main.c:1:12: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):x=!printf("%d\n",s);}
| ^~~~~
main.c:1:12: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:41: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
1 | s;main(x){~scanf("%d",&x)?main(s+=x):x=!printf("%d\n",s);}
| ^~~~~~
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:39: error: lvalue required as left operand of assignment
1 | s;main(x){~scanf("%d",&x)?main(s+=x):x=!printf("%d\n",s);}
| ^
|
s083153198 | p00251 | C | #include<stdio.h>
int main()
{
int a,i,b=0;
for(i=0;i<10;i++){
scanf("%d",&a);
b+=a;
}
printf("%d\n";b);
return 0;
} | main.c: In function 'main':
main.c:10:14: error: expected ')' before ';' token
10 | printf("%d\n";b);
| ~ ^
| )
|
s780804815 | p00251 | C | #include <stdio.h>
int main(){
int s, sum = 0;
for(i = 0; i < 10; i++){
scanf("%d", &s);
sum += s;
}
printf("%d\n", sum);
return 0;
} | main.c: In function 'main':
main.c:5:7: error: 'i' undeclared (first use in this function)
5 | for(i = 0; i < 10; i++){
| ^
main.c:5:7: note: each undeclared identifier is reported only once for each function it appears in
|
s734915122 | p00251 | C++ | #include<stdio.h>
int main(){
int i,sum=0,n;
for(i=0;i<10;i++){
cin >>n;
sum+=n;
}
cout << sum<<endl;
}
| a.cc: In function 'int main()':
a.cc:5:5: error: 'cin' was not declared in this scope
5 | cin >>n;
| ^~~
a.cc:8:3: error: 'cout' was not declared in this scope
8 | cout << sum<<endl;
| ^~~~
a.cc:8:16: error: 'endl' was not declared in this scope
8 | cout << sum<<endl;
| ^~~~
|
s375745247 | p00251 | C++ | import std.stream;
int main(){
int sum = 0;
for (i = 0; i < 10; i++){
int a;
a = readIn;
sum += a;
}
writef(%d\n, sum);
} | a.cc:9:10: error: stray '\' in program
9 | writef(%d\n, sum);
| ^
a.cc:1:1: error: 'import' does not name a type
1 | import std.stream;
| ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc: In function 'int main()':
a.cc:4:6: error: 'i' was not declared in this scope
4 | for (i = 0; i < 10; i++){
| ^
a.cc:6:5: error: 'readIn' was not declared in this scope
6 | a = readIn;
| ^~~~~~
a.cc:9:8: error: expected primary-expression before '%' token
9 | writef(%d\n, sum);
| ^
a.cc:9:9: error: 'd' was not declared in this scope
9 | writef(%d\n, sum);
| ^
a.cc:9:1: error: 'writef' was not declared in this scope
9 | writef(%d\n, sum);
| ^~~~~~
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.