submission_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 3 values | code stringlengths 1 522k | compiler_output stringlengths 43 10.2k |
|---|---|---|---|---|
s026495330 | p00718 | C++ | #include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
char output[80];
//mcxi¶ñ©çlÉÏ··éÌÉg¤Ö
int add(char a , int num){
if(a=='m') return (1000*num);
if(a=='c') return (100*num);
if(a=='x') return (10*num);
if(a=='i') return (1*num);
return 0;
}
//l©çmcxi¶ñÉÏ··éÌÉg¤Ö
void chengeNum(int num){
int index = 0, piyo, hoge;
char str[2];
char mcxi[5] = {'m','c','x','i','\0'};
//4ñ[vµÄ»ê¼êçESE\EêÌÊÌðßé
for(int i=0 ; i<4 ; i++){
//piyo:ÊÌ
hoge = 1;
for(int j=0 ; j<4-i ; j++){
hoge *= 10;
}
piyo = (num % hoge) / (hoge/10);
//ÊÌɶĶðüêé
if( piyo > 0){
if( piyo==1 ){
output[index] = mcxi[i];
index++;
}
else{
itoa( piyo , str , 10);
output[index] = str[0] ;
output[index+1] = mcxi[i];
index += 2;
}
output[index] = '\0';
}
}
}
int main(){
int dataSet, num1 , num2, hoge, length1, length2;
char input1[80], input2[80], piyo[2];
//f[^ZbgÌüÍ
scanf("%d", &dataSet);
//f[^Zbg̾¯üͳ¹é
for(int i=0 ; i<dataSet ; i++){
//ÏÌú»
num1 = 0;
num2 = 0;
//¶ñðQÂüÍ
scanf("%s %s", input1, input2);
//·³ðßé
length1 = strlen(input1);
length2 = strlen(input2);
//êÂÚÌüÍðlÉÏ··é
for(int a=0 ; a<length1 ; a++){
if(isdigit(input1[a])){
piyo[0] = input1[a];
num1 += add( input1[a+1] , atoi(piyo) );
a++;
}
else{
num1 += add( input1[a] , 1 );
}
}
//ñÂÚÌüÍðlÉÏ··é
for(int a=0 ; a<length2 ; a++){
if(isdigit(input2[a])){
piyo[0] = input2[a];
num2 += add( input2[a+1] , atoi(piyo) );
a++;
}
else{
num2 += add( input2[a] , 1 );
}
}
//lðmcxi¶ñÉÏ·µÄ¦ðoÍ
chengeNum(num1+num2);
printf("%s\n", output);
}
return 0;
} | a.cc: In function 'void chengeNum(int)':
a.cc:40:33: error: 'itoa' was not declared in this scope
40 | itoa( piyo , str , 10);
| ^~~~
|
s625228464 | p00718 | C++ | #include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
using namespace std;
char MCXI[] = "mcxi";
char mcxi[10];
char* toMCXI(int x) {
char str[8];
sprintf(str, "%04d", x);
int p = 0;
char* c = MCXI;
for (int i = 0; i < 4; i++, c++) {
int y = str[i] - '0';
if (y == 0) continue;
if (y == 1) {
mcxi[p] = *c;
p++;
}
else(2 <= y && y <= 9) {
mcxi[p] = y + '0';
mcxi[p+1] = *c;
p += 2;
}
}
return mcxi;
}
int toDec(char x[]) {
int p = 0;
int tmp = 1;
int results = 0;
for (int i = 0; x[i] != '\0'; i++) {
if ('2' <= x[i] && x[i] <= '9') {
tmp = x[i] - '0';
}
else {
for (; p < 4; p++) {
if (MCXI[p] == x[i]) {
results += pow(10, 3 - p) * tmp;
tmp = 1;
break;
}
}
}
}
return results;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
memset(mcxi, 0, sizeof(mcxi));
char a[8], b[8];
cin >> a >> b;
cout << toMCXI(toDec(a) + toDec(b)) << endl;
}
return 0;
} | a.cc: In function 'char* toMCXI(int)':
a.cc:22:39: error: expected ';' before '{' token
22 | else(2 <= y && y <= 9) {
| ^~
| ;
|
s759615071 | p00718 | C++ | #include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
using namespace std;
char MCXI[] = "mcxi";
string toMCXI(int x) {
string results;
char order[] = {'i', 'x', 'c', 'm'};
for (int i = 0; i < 4; i++)
{
int a = x % 10;
if (a != 0)
{
results.insert(results.begin(), order[i]);
if (a != 1)
{
results.insert(results.begin(), a + '0');
}
}
x /= 10;
}
return results;
}
int toDec(char x[]) {
int res = 0;
int n = 1;
for (int i = 0; x[i] != '\0'; i++)
{
char c = x[i];
switch(c)
{
case 'm':
res += n * 1000;
n = 1;
break;
case 'c':
res += n * 100;
n = 1;
break;
case 'x':
res += n * 10;
n = 1;
break;
case 'i':
res += n;
n = 1;
break;
default:
n = c - '0';
break;
}
}
return res;
}
int main() {
int n;
scanf("%d ", &n);
for (int i = 0; i < n; i++) {
char a[8], b[8], str[24];
gets(str);
sscanf(str, "%s%s", a, b);
cout << toMCXI(toDec(a) + toDec(b)) << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:65:17: error: 'gets' was not declared in this scope; did you mean 'getw'?
65 | gets(str);
| ^~~~
| getw
|
s210273285 | p00718 | C++ | import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
static int n;
static String s1, s2;
static char[] c = {'m', 'c', 'x', 'i'};
static int[] val = {1000, 100, 10, 1};
static int parse(String str) {
int ret = 0;
for(int i = 0; i < 4; i++) {
int pos = str.indexOf(c[i]);
if (pos > 0 && Character.isDigit(str.charAt(pos - 1))) {
ret += Integer.parseInt(str.substring(pos - 1, pos)) * val[i];
} else if(pos >= 0) {
ret += val[i];
}
}
return ret;
}
static String unparse(int num) {
String ret = "";
for(int i = 0; i < 4; i++) {
int num_ = num / val[i];
if(num_ > 1) {
ret += String.valueOf(num_) + c[i];
} else if(num_ == 1) {
ret += c[i];
}
num = num % val[i];
}
return ret;
}
public static void main(String[] args) {
n = sc.nextInt();
for(int i = 0; i < n; i++) {
s1 = sc.next();
s2 = sc.next();
System.out.println(unparse(parse(s1) + parse(s2)));
}
}
} | a.cc:1:1: error: 'import' does not name a type
1 | import java.util.*;
| ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: expected unqualified-id before 'public'
3 | public class Main {
| ^~~~~~
|
s405907219 | p00718 | C++ | #include <iostream>
#include <string>
#include <sstream>
using namespace std;
const string MCXI = "ixcm";
int MCXI2Int(string s)
{
int res = 0, tmp = 1;
for (unsigned int i = 0; i < s.size(); ++i) {
if (isdigit(s[i])) {
tmp = s[i]-'0';
} else {
if (s[i] == 'm') {
res += tmp * 1000;
} else if (s[i] == 'c') {
res += tmp * 100;
} else if (s[i] == 'x') {
res += tmp * 10;
} else {
res += tmp;
}
tmp = 1;
}
}
return res;
}
string Int2MCXI(int n)
{
stringstream ss;
ss << n;
string res = ss.str();
reverse(res.begin(), res.end());
unsigned int t = 0;
for (string::iterator it = res.begin(); it != res.end(); ) {
if (*it == '0') {
it = res.erase(it);
++t;
} else if (*it == '1') {
*it = MCXI[t++];
++it;
} else {
it = res.insert(it, MCXI[t++]);
it += 2;
}
}
reverse(res.begin(), res.end());
return res;
}
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s, t;
cin >> s >> t;
cout << Int2MCXI(MCXI2Int(s) + MCXI2Int(t)) << endl;
}
return 0;
} | a.cc: In function 'std::string Int2MCXI(int)':
a.cc:35:3: error: 'reverse' was not declared in this scope
35 | reverse(res.begin(), res.end());
| ^~~~~~~
|
s474444740 | p00718 | C++ | ude <iostream>
#include <string>
using namespace std;
int n;
int mcxi2int(string str,int pt)
{
if( pt >= str.size() )
return 0;
if( str[pt] >= '2' && str[pt] <= '9' )
pt++;
int d;
if(str[pt] == 'm')
d = 1000;
else if(str[pt] == 'c')
d = 100;
else if(str[pt] == 'x')
d = 10;
else
d = 1;
if( pt-1 >= 0 && str[pt-1] >= '2' && str[pt-1] <= '9')
return d*(str[pt-1]-'0') + mcxi2int(str, pt+1);
else
return d + mcxi2int(str, pt+1);
}
string int2mcxi(int k)
{
int i = k;
string str = "";
if( i >= 1000 )
{
if( i/1000 >= 2)
str += '0' + i/1000;
str += 'm';
}
i = i%1000;
if( i >= 100 )
{
if( i/100 >= 2)
str += '0' + i/100;
str += 'c';
}
i = i%100;
if( i >= 10 )
{
if( i/10 >= 2)
str += '0' + i/10;
str += 'x';
}
i = i%10;
if( i >= 1 )
{
if( i >= 2)
str += '0' + i;
str += 'i';
}
return str;
}
int main()
{
cin >> n;
for( int i = 0; i < n; i++)
{
string mcxi1, mcxi2;
cin >> mcxi1 >> mcxi2;
string out = int2mcxi(mcxi2int(mcxi1, 0) + mcxi2int(mcxi2, 0));
cout << out << endl;
}
return 0;
} | a.cc:1:1: error: 'ude' does not name a type
1 | ude <iostream>
| ^~~
In file included from /usr/include/c++/14/bits/char_traits.h:42,
from /usr/include/c++/14/string:42,
from a.cc:2:
/usr/include/c++/14/bits/postypes.h:68:11: error: 'ptrdiff_t' does not name a type
68 | typedef ptrdiff_t streamsize; // Signed integral type
| ^~~~~~~~~
/usr/include/c++/14/bits/postypes.h:41:1: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
40 | #include <cwchar> // For mbstate_t
+++ |+#include <cstddef>
41 |
In file included from /usr/include/c++/14/bits/char_traits.h:50:
/usr/include/c++/14/type_traits:666:33: error: 'nullptr_t' is not a member of 'std'
666 | struct is_null_pointer<std::nullptr_t>
| ^~~~~~~~~
/usr/include/c++/14/type_traits:666:42: error: template argument 1 is invalid
666 | struct is_null_pointer<std::nullptr_t>
| ^
/usr/include/c++/14/type_traits:670:48: error: template argument 1 is invalid
670 | struct is_null_pointer<const std::nullptr_t>
| ^
/usr/include/c++/14/type_traits:674:51: error: template argument 1 is invalid
674 | struct is_null_pointer<volatile std::nullptr_t>
| ^
/usr/include/c++/14/type_traits:678:57: error: template argument 1 is invalid
678 | struct is_null_pointer<const volatile std::nullptr_t>
| ^
/usr/include/c++/14/type_traits:1429:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
1429 | : public integral_constant<std::size_t, alignof(_Tp)>
| ^~~~~~
In file included from /usr/include/wchar.h:35,
from /usr/include/c++/14/cwchar:44,
from /usr/include/c++/14/bits/postypes.h:40:
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/type_traits:1429:57: error: template argument 1 is invalid
1429 | : public integral_constant<std::size_t, alignof(_Tp)>
| ^
/usr/include/c++/14/type_traits:1429:57: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1438:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
1438 | : public integral_constant<std::size_t, 0> { };
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/type_traits:1438:46: error: template argument 1 is invalid
1438 | : public integral_constant<std::size_t, 0> { };
| ^
/usr/include/c++/14/type_traits:1438:46: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1440:26: error: 'std::size_t' has not been declared
1440 | template<typename _Tp, std::size_t _Size>
| ^~~
/usr/include/c++/14/type_traits:1441:21: error: '_Size' was not declared in this scope
1441 | struct rank<_Tp[_Size]>
| ^~~~~
/usr/include/c++/14/type_traits:1441:27: error: template argument 1 is invalid
1441 | struct rank<_Tp[_Size]>
| ^
/usr/include/c++/14/type_traits:1442:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/type_traits:1442:65: error: template argument 1 is invalid
1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
| ^
/usr/include/c++/14/type_traits:1442:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:1446:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/type_traits:1446:65: error: template argument 1 is invalid
1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
| ^
/usr/include/c++/14/type_traits:1446:65: note: invalid template non-type parameter
/usr/include/c++/14/type_traits:2086:26: error: 'std::size_t' has not been declared
2086 | template<typename _Tp, std::size_t _Size>
| ^~~
/usr/include/c++/14/type_traits:2087:30: error: '_Size' was not declared in this scope
2087 | struct remove_extent<_Tp[_Size]>
| ^~~~~
/usr/include/c++/14/type_traits:2087:36: error: template argument 1 is invalid
2087 | struct remove_extent<_Tp[_Size]>
| ^
/usr/include/c++/14/type_traits:2099:26: error: 'std::size_t' has not been declared
2099 | template<typename _Tp, std::size_t _Size>
| ^~~
/usr/include/c++/14/type_traits:2100:35: error: '_Size' was not declared in this scope
2100 | struct remove_all_extents<_Tp[_Size]>
| ^~~~~
/usr/include/c++/14/type_traits:2100:41: error: template argument 1 is invalid
2100 | struct remove_all_extents<_Tp[_Size]>
| ^
/usr/include/c++/14/type_traits:2171:12: error: 'std::size_t' has not been declared
2171 | template<std::size_t _Len>
| ^~~
/usr/include/c++/14/type_traits:2176:30: error: '_Len' was not declared in this scope
2176 | unsigned char __data[_Len];
| ^~~~
/usr/include/c++/14/type_traits:2194:12: error: 'std::size_t' has not been declared
2194 | template<std::size_t _Len, std::size_t _Align =
| ^~~
/usr/include/c++/14/type_traits:2194:30: error: 'std::size_t' has not been declared
2194 | template<std::size_t _Len, std::size_t _Align =
| ^~~
/usr/include/c++/14/type_traits:2195:55: error: '_Len' was not declared in this scope
2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)>
| ^~~~
/usr/include/c++/14/type_traits:2195:59: error: template argument 1 is invalid
2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)>
| ^
/usr/include/c++/14/type_traits:2202:30: error: '_Len' was not declared in this scope
2202 | unsigned char __data[_Len];
| ^~~~
/usr/include/c++/14/type_traits:2203:44: error: '_Align' was not declared in this scope
2203 | struct __attribute__((__aligned__((_Align)))) { } __align;
| ^~~~~~
/usr/include/c++/14/bits/char_traits.h:144:61: error: 'std::size_t' has not been declared
144 | compare(const char_type* __s1, const char_type* __s2, std::size_t __n);
| ^~~
/usr/include/c++/14/bits/char_traits.h:146:40: error: 'size_t' in namespace 'std' does not name a type
146 | static _GLIBCXX14_CONSTEXPR std::size_t
| ^~~~~~
/usr/include/c++/14/bits/char_traits.h:150:34: error: 'std::size_t' has not been declared
150 | find(const char_type* __s, std::size_t __n, const char_type& __a);
| ^~~
/usr/include/c++/14/bits/char_traits.h:153:52: error: 'std::size_t' has not been declared
153 | move(char_type* __s1, const char_type* __s2, std::size_t __n);
| ^~~
/usr/include/c++/14/bits/char_traits.h:156:52: error: 'std::size_t' has not been declared
156 | copy(char_type* __s1, const char_type* __s2, std::size_t __n);
| ^~~
/usr/include/c++/14/bits/char_traits.h:159:30: error: 'std::size_t' has not been declared
159 | assign(char_type* __s, std::size_t __n, char_type __a);
| ^~~
/usr/include/c++/14/bits/char_traits.h:187:59: error: 'std::size_t' has not been declared
187 | compare(const char_type* __s1, const char_type* __s2, std::size_t __n)
| ^~~
/usr/include/c++/14/bits/char_traits.h: In static member function 'static constexpr int __gnu_cxx::char_traits<_CharT>::compare(const char_type*, const char_type*, int)':
/usr/include/c++/14/bits/char_traits.h:189:17: error: 'size_t' is not a member of 'std'; did you mean 'size_t'?
189 | for (std::size_t __i = 0; __i < __n; ++__i)
| ^~~~~~
/usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here
214 | typedef __SIZE_TYPE__ size_t;
| ^~~~~~
/usr/include/c++/14/bits/char_traits.h:189:33: error: '__i' was not declared in this scope; did you mean '__n'?
189 | for (std::size_t __i = 0; __i < __n; ++__i)
| ^~~
| __n
/usr/include/c++/14/bits/char_traits.h: At global scope:
/usr/include/c++/14/bits/char_traits.h:198:31: error: 'size_t' in namespace 'std' does not name a type
198 | _GLIBCXX14_CONSTEXPR std::size_t
| |
s041358195 | p00718 | C++ | #include <stdio.h>
#include <algorithm>
using namespace std;
int n;
char k[2][9];
void init() {
scanf("%d", &n);
}
bool input() {
int i;
if (!n) return false;
n--;
scanf("%s", k[0]);
scanf("%s", k[1]);
return true;
}
int main() {
int i, j, a, num[2];
init();
while (input()) {
a = 1;
for (i = 0; i < 2; i++) {
num[i] = 0;
for (j = 0; j < strlen(k[i]); j++) {
switch (k[i][j]) {
case 'm':
num[i] += a * 1000;
a = 1;
break;
case 'c':
num[i] += a * 100;
a = 1;
break;
case 'x':
num[i] += a * 10;
a = 1;
break;
case 'i':
num[i] += a;
a = 1;
break;
default:
a = k[i][j] - '0';
break;
}
//printf("%d\n", num[i]);
}
}
num[0] += num[1];
a = num[0] / 1000;
num[0] %= 1000;
if (a > 0) {
if (a > 1) {
printf("%d", a);
}
printf("m");
}
a = num[0] / 100;
num[0] %= 100;
if (a > 0) {
if (a > 1) {
printf("%d", a);
}
printf("c");
}
a = num[0] / 10;
num[0] %= 10;
if (a > 0) {
if (a > 1) {
printf("%d", a);
}
printf("x");
}
a = num[0];
if (a > 0) {
if (a > 1) {
printf("%d", a);
}
printf("i");
}
printf("\n");
}
return 0;
} | a.cc: In function 'int main()':
a.cc:32:23: error: 'strlen' was not declared in this scope
32 | for (j = 0; j < strlen(k[i]); j++) {
| ^~~~~~
a.cc:3:1: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include <algorithm>
+++ |+#include <cstring>
3 | using namespace std;
|
s749773552 | p00718 | C++ | #include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define INDEX(s,c) (find(s.begin(),s.end(),c)-s.begin())
char mcxi="mcxi";
int decode(string s){
int i,no=s.size();
int res=0;
int m = 1000;
for(int i=0;i<4;i++){
int j = INDEX(s,mcxi[i]);
if(j && isdigit(s[j-1]))res += m*(s[j-1]-'0');
else res += m;
m/=10;
}
return res;
}
string encode(int n){
string res;
if(n%10){
res += 'i';
if(1<n%10)res += '0'+n%10;
}
n/=10;
if(n%10){
res += 'x';
if(1<n%10)res += '0'+n%10;
}
n/=10;
if(n%10){
res += 'c';
if(1<n%10)res += '0'+n%10;
}
n/=10;
if(n%10){
res += 'm';
if(1<n%10)res += '0'+n%10;
}
reverse(res.begin(),res.end());
return res;
}
int main(){
int n;
cin>>n;
while(n--){
string s,t;
cin>>s>>t;
int a=decode(s),b=decode(t);
//cout<<a+b<<endl;
cout<<encode(a+b)<<endl;
}
return 0;
} | a.cc:11:11: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
11 | char mcxi="mcxi";
| ^~~~~~
| |
| const char*
a.cc: In function 'int decode(std::string)':
a.cc:17:37: error: invalid types 'char[int]' for array subscript
17 | int j = INDEX(s,mcxi[i]);
| ^
a.cc:10:44: note: in definition of macro 'INDEX'
10 | #define INDEX(s,c) (find(s.begin(),s.end(),c)-s.begin())
| ^
|
s121625511 | p00718 | C++ | #include<iostream>
#include<string>
using namespace std;
int dec(string s)
{
int ans=0;
int co=1;
for(int i = 0; i < s.size(); ++i)
{
if(s[i]=='m')
{
ans+=co*1000; co=1;
}
else if(s[i]=='c')
{
ans+=co*100;
co=1;
}
else if(s[i]=='x')
{
ans+=co*10;
co=1;
}
else if(s[i]=='i')
{
ans+=co;
co=1;
}
else co=s[i]-'0';
}
return ans;
}
string enc(int n)
{
char s[1001];
s[1]='i'; s[10]='x'; s[100]='c'; s[1000]='m';
int pos=1;
string ans="";
while(n)
{
int tmp=n%10;
n/=10;
if(tmp==0)
{
pos*=10;
continue;
}
else
{
if(tmp==1) ans+=s[pos];
else
{
ans+=s[pos];
ans+=tmp+'0';
}
}
pos*=10;
}
reverse(ans.begin(),ans.end());
return ans;
}
int main()
{
int n;
cin>>n;
while(n--)
{
string s1,s2;
cin>>s1>>s2;
cout<<enc(dec(s1)+dec(s2))<<endl;
}
return 0;
} | a.cc: In function 'std::string enc(int)':
a.cc:60:9: error: 'reverse' was not declared in this scope
60 | reverse(ans.begin(),ans.end());
| ^~~~~~~
|
s561235441 | p00718 | C++ | null | a.cc:1:1: error: 'null' does not name a type
1 | null
| ^~~~
|
s082186019 | p00718 | C++ | #include "MyLib.h"
#include "Measure.h"
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void) {
int n;
string a, b, ans;
int num1[4], num2[4], nans[4];
int ch_point;
char ch[4] = {'i', 'x', 'c', 'm'};
bool increase;
cin >> n;
while(n--) {
increase = false;
string ans = "";
cin >> a >> b;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for(int i = 0; i < 4; i++) {
ch_point = a.find(ch[i]);
if(ch_point == string::npos) num1[i] = 0;
else if(ch_point == a.size() - 1) num1[i] = 1;
else if('2' <= a[ch_point + 1] && a[ch_point + 1] <= '9') num1[i] = a[ch_point + 1] - '0';
else num1[i] = 1;
ch_point = b.find(ch[i]);
if(ch_point == string::npos) num2[i] = 0;
else if(ch_point == b.size() - 1) num2[i] = 1;
else if('2' <= b[ch_point + 1] && b[ch_point + 1] <= '9') num2[i] = b[ch_point + 1] - '0';
else num1[i] = 1;
nans[i] = num1[i] + num2[i] + (increase ? 1 : 0);
increase = false;
if(nans[i] > 9) {
nans[i] -= 10;
increase = true;
}
switch(nans[i]) {
case 0: break;
case 1: ans += ch[i]; break;
default: ans += ch[i]; ans += nans[i] + '0'; break;
};
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
return 0;
} | a.cc:1:10: fatal error: MyLib.h: No such file or directory
1 | #include "MyLib.h"
| ^~~~~~~~~
compilation terminated.
|
s036021339 | p00718 | C++ | #include <iostream>
#include <string>
using namespace std;
int main(void) {
int n;
string a, b, ans;
int num1[4], num2[4], nans[4];
int ch_point;
char ch[4] = {'i', 'x', 'c', 'm'};
bool increase;
cin >> n;
while(n--) {
increase = false;
string ans = "";
cin >> a >> b;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
for(int i = 0; i < 4; i++) {
ch_point = a.find(ch[i]);
if(ch_point == string::npos) num1[i] = 0;
else if(ch_point == a.size() - 1) num1[i] = 1;
else if('2' <= a[ch_point + 1] && a[ch_point + 1] <= '9') num1[i] = a[ch_point + 1] - '0';
else num1[i] = 1;
ch_point = b.find(ch[i]);
if(ch_point == string::npos) num2[i] = 0;
else if(ch_point == b.size() - 1) num2[i] = 1;
else if('2' <= b[ch_point + 1] && b[ch_point + 1] <= '9') num2[i] = b[ch_point + 1] - '0';
else num1[i] = 1;
nans[i] = num1[i] + num2[i] + (increase ? 1 : 0);
increase = false;
if(nans[i] > 9) {
nans[i] -= 10;
increase = true;
}
switch(nans[i]) {
case 0: break;
case 1: ans += ch[i]; break;
default: ans += ch[i]; ans += nans[i] + '0'; break;
};
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:19:17: error: 'reverse' was not declared in this scope
19 | reverse(a.begin(), a.end());
| ^~~~~~~
|
s668077654 | p00719 | Java | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
class Main{
static int kyori[][];
static boolean visited[];
static double answer;
static int n, m, b;
static Integer tickets[];
public static void main(String args[]){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
while(true){
String strs[] = br.readLine().split(" ");
n = Integer.parseInt(strs[0]); // 馬車券の数
if(n == 0) return;
tickets = new Integer[n];
m = Integer.parseInt(strs[1]); // 都市の数
kyori = new int[m][m];
visited = new boolean[m];
int p = Integer.parseInt(strs[2]); // 道路の数
int a = Integer.parseInt(strs[3]) - 1; // スタート
b = Integer.parseInt(strs[4]) - 1; // ゴール
// チケット
strs = br.readLine().split(" ");
for(int i = 0; i < n; i++){
tickets[i] = Integer.parseInt(strs[i]);
}
Arrays.sort(tickets, Collections.reverseOrder());
// printArray(tickets);
// 道
for(int i = 0; i < p; i++){
strs = br.readLine().split(" ");
int x = Integer.parseInt(strs[0]) - 1;
int y = Integer.parseInt(strs[1]) - 1;
int z = Integer.parseInt(strs[2]);
kyori[x][y] = z;
kyori[y][x] = z;
}
// printMatrix(kyori);
answer = 0.0;
Integer distance[] = new Integer[n];
for(int i = 0; i < n; i++){
distance[i] = 0;
}
dfs(a, 0, distance);
if(answer == 0.0){
System.out.println("Impossible");
}else{
System.out.println(answer);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void dfs(int now, int count, Integer distance[]){
// 到達したかどうか
if(now == b){
// System.out.println("到達しました");
printArray(distance);
Integer dis_clone[] = distance.clone();
Arrays.sort(dis_clone, Collections.reverseOrder());
double result_temp = 0.0;
for(int i = 0; i < count; i++){
result_temp += (double)dis_clone[i] / (double)tickets[i];
}
// System.out.println(result_temp);
if(answer == 0.0){
answer = result_temp;
}else if(answer > result_temp){
answer = result_temp;
}
printArray(visited);
return;
}
// 馬券の枚数を超えていないか
// 注意 馬券の枚数を0スタートにしてる
if(count >= n || count >= m) return;
// System.out.println("今の場所: " + now + "\tゴール: " + b);
visited[now] = true;
// 次の都市へ
for(int i = 0; i < m; i++){
// 行ける都市かどうか確認
if(kyori[now][i] != 0 && !visited[i]){
System.out.println("次の街へ: " + i + "\t今の街: " + now);
distance[count] = kyori[now][i];
dfs(i, count + 1, distance);
distance[count] = 0;
System.out.println("backtrack");
}
}
visited[now] = false;
}
/*
public static void printArray(int array[]){
for(int i = 0; i < array.length; i++)
System.out.print(array[i] + "\t");
System.out.println();
}
public static void printArray(Integer array[]){
for(int i = 0; i < array.length; i++)
System.out.print(array[i] + "\t");
System.out.println();
}
public static void printArray(boolean array[]){
for(int i = 0; i < array.length; i++)
System.out.print(array[i] + "\t");
System.out.println();
}
public static void printMatrix(int matrix[][]){
for(int i = 0; i < matrix.length; i++){
printArray(matrix[i]);
}
}
public static void printMatrix(boolean matrix[][]){
for(int i = 0; i < matrix.length; i++){
printArray(matrix[i]);
}
}
*/
} | Main.java:73: error: cannot find symbol
printArray(distance);
^
symbol: method printArray(Integer[])
location: class Main
Main.java:87: error: cannot find symbol
printArray(visited);
^
symbol: method printArray(boolean[])
location: class Main
2 errors
|
s528659850 | p00719 | C | #include <iostream>
#include <algorithm>
#define INF 99999999
using namespace std;
int main(void){
while(1){
int n, m, p, a, b; cin >> n >> m >> p >> a >> b;
if(!n && !m && !p && !a && !b) break;
int t[10]={0};
int cost[30][30]; fill(cost[0], cost[29], -1);
double dp[(1<<8)+1][30]; fill(dp[0], dp[(1<<8)], INF);
for(int i=0; i<n; i++){
cin >> t[i];
}
for(int i=0; i<p; i++){
int x, y, z; cin >> x >> y >> z;
x--; y--;
cost[x][y] = cost[y][x] = z;
}
dp[(1<<n)-1][b-1] = 0;
double ans = INF;
for(int s=(1<<n)-1; s>=0; s--){
ans = min(ans, dp[s][a-1]);
for(int v=0; v<m; v++){
for(int i=0; i<n; i++){
if(s >> i & 1){
for(int u=0; u<m; u++){
if(cost[v][u] >= 0){
dp[s & ~(1<<i)][u] = min(dp[s & ~(1<<i)][u], dp[s][v]+(double)cost[v][u]/t[i]);
}
}
}
}
}
}
if(ans == INF) cout << "Impossible" << endl;
else cout << ans << endl;
}
return 0;
}
| main.c:1:10: fatal error: iostream: No such file or directory
1 | #include <iostream>
| ^~~~~~~~~~
compilation terminated.
|
s076349621 | p00719 | C | #include <stdio.h>
#include <string.h>
#define INF 0x3FFFFFFF
struct edge{
int x;
int y;
int z;
};
int main(void){
int n, m, p, a, b, t[8], i, j, k, l;
double d[30][1 << 8], ans;
struct edge e[200];
while(1){
scanf("%d%d%d%d%d",&n,&m,&p,&a,&b);
if(n == 0 && m == 0 && p == 0 && a == 0 && b == 0) break;
a--, b--;
for(i = 0;i < n;i++)
scanf("%d",&t[i]);
for(i = 0;i < p;i++){
scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].z);
e[i].x = e[i].x - 1,e[i].y = e[i].y - 1;
}
for(i = 0;i < p;i++)
e[i + p].x = e[i].y, e[i + p].y = e[i].x, e[i + p].z = e[i].z;
for(i = 0;i < m;i++)
for(j = 0;j < (1 << n);j++) d[i][j] = (double) INF;
d[a][(1 << n) - 1] = 0.0;
for(i = 0;i < m;i++){ // max arith 30
for(j = 0;j < p * 2;j++){ // max arith 100
for(k = 0;k < (1 << n);k++){ // max arith 256
for(l = 0;l < n;l++){ // max arith 8
if(k & (1 << l) && d[e[j].y][k - (1 << l)] > d[e[j].x][k] + (double) e[j].z / t[l]) d[e[j].y][k - (1 << l)] = d[e[j].x][k] + (double) e[j].z / t[l];
}
}
}
}
ans = (double)INF;
for(i = 0;i < (1 << n);i++)
if(ans > d[b][i]) ans = d[b][i];
if(ans != (double)INF)
printf("%.3f\n",ans);
else
printf("Impossible\n");
}
return 0; | main.c: In function 'main':
main.c:47:9: error: expected declaration or statement at end of input
47 | return 0;
| ^~~~~~
|
s019902042 | p00719 | C++ | #include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define INF 2000000000
#define pb push_back
int N, M, P, a, b;
int t[10];
struct edge
{
int to;
double cost;
edge(int to, double cost):to(to), cost(cost){}
};
vector<edge> g[40];
double dp[40][1<<8];
double rec(int v, int bit)
{
if(dp[v][bit]!=-1)return dp[v][bit];
double res = INF;
for(int i=0; i<g[v].size(); i++)
{
int u = g[v][i].to;
double cost = g[v][i].cost;
for(int j=0; j<N; j++)
{
if(!((bit>>j)&1))
{
res=min(res, rec(u, bit|(1<<j))+cost/t[j]);
}
}
}
return dp[v][bit]=res;
}
int main()
{
while(1)
{
for(int i=0; i<40; i++)g[i].clear();
scanf("%d %d %d %d %d", &N, &M, &P, &a, &b);
if(N==0&&M==0&&P==0&&a==0&&b==0)break;
a--; b--;
for(int i=0; i<N; i++)scanf("%d", &t[i]);
for(int i=0; i<P; i++)
{
int x, y;
double z;
scanf("%d %d %lf", &x, &y, &z);
x--; y--;
g[x].pb(edge(y, z));
g[y].pb(edge(x, z));
}
for(int i=0; i<M; i++)for(int j=0; j<(1<<N); j++)dp[i][j]=-1;
dp[a][(1<<N)-1]=0;
double ans = INF;
for(int i=0; i<(1<<N); i++)ans = min(ans, rec(b, i));
if(ans == INF)printf("Impossible\n");
else prinatf("%f\n", ans);
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:58:22: error: 'prinatf' was not declared in this scope; did you mean 'printf'?
58 | else prinatf("%f\n", ans);
| ^~~~~~~
| printf
|
s609829454 | p00719 | C++ |
#include<bits/stdc++.h>
using namespace std;
#define P pair<int,double>
#define to first
#define cost second
#define PB push_back
void f(int n,int m,int p,int a,int b){
vector<double> t(n);
vector<vector<P>> es(m+1);
for(int i=0;i<n;i++){
cin>>t[i];
}
for(int i=0;i<p;i++){
int x,y,z;
cin>>x>>y>>z;
es[x].PB(P(y,z));
es[y].PB(P(x,z));
}
vector<vector<double>> dp(1<<n,vector<double>(m+1,DBL_MAX));
dp[0][a]=0;
for(int i=0;i<(1<<n);i++){
for(int j=1;j<=m;j++){
if(dp[i][j]==DBL_MAX) continue;
for(int k=0;k<n;k++){
if(i&(1<<k)) continue;
for(auto e:es[j]){
if(dp[i|(1<<k)][e.to]>dp[i][j]+e.cost/t[k]){
dp[i|(1<<k)][e.to]=dp[i][j]+e.cost/t[k];
flag=true;
}
}
}
}
}
double ans=DBL_MAX;
for(int i=0;i<(1<<n);i++)
ans=min(ans,dp[i][b]);
if(ans==DBL_MAX){
cout<<"Impossible"<<endl;
}else{
printf("%.10lf\n",(ans==DBL_MAX?-1:ans));
}
}
int main(){
int n,m,p,a,b;
while(true){
cin>>n>>m>>p>>a>>b;
if(n==0) break;
f(n,m,p,a,b);
}
}
| a.cc: In function 'void f(int, int, int, int, int)':
a.cc:38:13: error: 'flag' was not declared in this scope
38 | flag=true;
| ^~~~
|
s446915695 | p00719 | C++ | #include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define INF 10000
#define MAXN 30
#define MAXM 8
int T[MAXN];
int G[MAXM][MAXM];
double dp[MAXM][1 << MAXN];
bool used[MAXM][1 << MAXN];
int n, m, p, a, b;
double dijkstra(){
for (int i = 0; i < MAXM; i++) {
for (int j = 0; j < (1 << MAXN); j++) {
dp[i][j] = INF;
used[i][j] = false;
}
}
dp[a][(1 << n) - 1] = 0;
while (true) {
int v = -1;
int w;
for (int u = 0; u < m; u++) {
for (int s = 0; s < (1 << n); s++) {
if (!used[u][s] && (v == -1 || dp[u][s] < dp[v][s])) {
v = u; w = s;
}
}
}
if (v == -1) {
break;
}
used[v][w] = true;
for (int u = 0; u < m; u++) {
for (int i = 0; i < n; i++) {
if (G[v][u] == INF) {
continue;
}
if (w >> i & 1) {
dp[u][w & ~(1 << i)] = min(dp[u][w & ~(1 << i)], dp[v][w] + (double)G[v][u] / T[i]);
}
}
}
}
// for (int i = 0; i < m; i++) {
// for (int j = 0; j < (1<<n); j++) {
// cout << dp[i][j] <<" ";
// }
// cout << endl;
// }
double ans = INF;
for (int i = 0; i < (1 << n); i++) {
ans = min(ans, dp[b][i]);
}
return ans;
}
int main()
{
int x, y ,z;
while (true) {
cin >> n >> m >> p >> a >> b;
if (n == 0 && m == 0) {
break;
}
a--; b--;
for (int i = 0; i < MAXM; i++) {
for (int j = 0; j < MAXM; j++) {
G[i][j] = INF;
}
}
for (int i = 0; i < MAXM; i++) {
G[i][i] = 0;
}
for (int i = 0; i < n; i++) {
cin >> T[i];
}
for (int i = 0; i < p; i++) {
cin >> x >> y >> z;
x--; y--;
G[x][y] = G[y][x] = z;
}
double res = dijkstra();
if (res == INF) {
cout << "Impossible" << endl;
}else{
printf("%.3f\n", res);
}
}
return 0;
} | /tmp/ccJfHiNs.o: in function `dijkstra()':
a.cc:(.text+0x5d): relocation truncated to fit: R_X86_64_PC32 against symbol `used' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x80): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x86): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0xf0): relocation truncated to fit: R_X86_64_PC32 against symbol `used' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x16b): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x189): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x1b5): relocation truncated to fit: R_X86_64_PC32 against symbol `used' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x322): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x335): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x360): relocation truncated to fit: R_X86_64_PC32 against symbol `b' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x3a3): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status
|
s392815097 | p00719 | C++ | #include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<queue>
using namespace std;
struct Edge{
int to;
int cost;
Edge(){};
Edge(int _to,int _cost){
to = _to;
cost = _cost;
}
};
struct Data{
int pos;
int tic;
double t;
Data(){};
Data(int _pos,int _tic,double _t){
pos = _pos;
tic = _tic;
t = _t;
}
bool operator<(const Data &d)const{
return t > d.t;
}
};
int main(){
int n,m,p,a,b;
while(cin>>n>>m>>p>>a>>b,n||m||p||a||b){
int tick[10];
for(int i = 0;i < n;i++)cin>>tick[i];
vector<Edge> Node[50];
for(int i = 0;i < p;i++){
int x,y,z;
cin>>x>>y>>z;
Node[x].push_back(Edge(y,z));
Node[y].push_back(Edge(x,z));
}
//cout<<"!"<<endl;
priority_queue<Data> Q;
Q.push(Data(a,0,0));
double vis[50][1000];
for(int i = 0;i < 1000;i++){
for(int j = 0;j < 50;j++){
vis[j][i] = 1e+9;
}
}
vis[a][0] = 0;
bool flg = false;
while(!Q.empty()){
Data D = Q.top();Q.pop();
//if(D.t<3)cout<<D.pos<<" "<<D.tic<<" "<<D.t<<endl;
int Pos = D.pos;
if(vis[Pos][D.tic] < D.t)continue;
vis[Pos][D.tic] = D.t;
for(int i = 0;i < Node[Pos].size();i++){
Edge e = Node[Pos][i];
for(int j = 0;j < n;j++){
if((1<<j)&D.tic)continue;
int c = D.tic|(1<<j);
double nt = D.t + ((double)e.cost/(double)tick[j]);
if(vis[e.to][c] < nt)continue;
vis[e.to][c] = nt;
Q.push(Data(e.to,c,nt));
}
}
}
int ans = 1e+9;
for(int i = 0;i < (1<<8);i++)ans = min(ans,vis[b][i]);
if(ans == 1e+9)cout<<"Impossible"<<endl;
else cout<<ans<<endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:73:47: error: no matching function for call to 'min(int&, double&)'
73 | for(int i = 0;i < (1<<8);i++)ans = min(ans,vis[b][i]);
| ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
233 | min(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed:
a.cc:73:47: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'double')
73 | for(int i = 0;i < (1<<8);i++)ans = min(ans,vis[b][i]);
| ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:2:
/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:73:47: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
73 | for(int i = 0;i < (1<<8);i++)ans = min(ans,vis[b][i]);
| ~~~^~~~~~~~~~~~~~~
|
s174960587 | p00719 | C++ | #include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct edge{int to,cost;};
struct data{
int pos,state;
double cost;
bool operator>(const data &d)const{
return cost>d.cost;
}
};
vector<edge>g[32];
const double INF=1e9+7;
double d[32][1024];
int t[16];
int n,m,p,a,b;
int main(){
while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b),n||m||p||a||b){
a--;b--;
for(int i=0;i<m;i++){
g[i].clear();
}
fill(dp[0],32*1024,INF);
for(int i=0;i<n;i++)scanf("%d",&t[i]);
for(int i=0;i<p;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
x--;y--;
g[x].push_back((edge){y,z});
g[y].push_back((edge){x,z});
}
priority_queue<data,vector<data>,greater<data> >Q;
Q.push((data){a,0,0});
while(Q.size()){
data a=Q.top();Q.pop();
if(d[a.pos][a.state]<a.cost)continue;
d[a.pos][a.state]=a.cost;
for(int i=0;i<g[a.pos].size();i++){
edge &e=g[a.pos][i];
for(int j=0;j<n;j++){
if((a.state>>j)&1)continue;
Q.push((data){e.to,a.state|(1<<j),a.cost+(double)e.cost/t[j]});
}
}
}
double mi=INF;
for(int i=0;i<(1<<n);i++){
mi=min(mi,d[b][i]);
}
if(mi==INF)puts("Impossible");
else printf("%.6f\n",mi);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:25:14: error: 'dp' was not declared in this scope; did you mean 'p'?
25 | fill(dp[0],32*1024,INF);
| ^~
| p
a.cc:34:40: error: template argument 1 is invalid
34 | priority_queue<data,vector<data>,greater<data> >Q;
| ^
a.cc:34:40: error: template argument 2 is invalid
a.cc:34:54: error: template argument 1 is invalid
34 | priority_queue<data,vector<data>,greater<data> >Q;
| ^
a.cc:34:56: error: template argument 1 is invalid
34 | priority_queue<data,vector<data>,greater<data> >Q;
| ^
a.cc:34:56: error: template argument 2 is invalid
a.cc:34:56: error: template argument 3 is invalid
a.cc:35:11: error: request for member 'push' in 'Q', which is of non-class type 'int'
35 | Q.push((data){a,0,0});
| ^~~~
a.cc:35:17: error: reference to 'data' is ambiguous
35 | Q.push((data){a,0,0});
| ^~~~
In file included from /usr/include/c++/14/vector:69,
from a.cc:3:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'struct data'
7 | struct data{
| ^~~~
a.cc:36:17: error: request for member 'size' in 'Q', which is of non-class type 'int'
36 | while(Q.size()){
| ^~~~
a.cc:37:13: error: reference to 'data' is ambiguous
37 | data a=Q.top();Q.pop();
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'struct data'
7 | struct data{
| ^~~~
a.cc:37:30: error: request for member 'pop' in 'Q', which is of non-class type 'int'
37 | data a=Q.top();Q.pop();
| ^~~
a.cc:38:20: error: request for member 'pos' in 'a', which is of non-class type 'int'
38 | if(d[a.pos][a.state]<a.cost)continue;
| ^~~
a.cc:38:27: error: request for member 'state' in 'a', which is of non-class type 'int'
38 | if(d[a.pos][a.state]<a.cost)continue;
| ^~~~~
a.cc:38:36: error: request for member 'cost' in 'a', which is of non-class type 'int'
38 | if(d[a.pos][a.state]<a.cost)continue;
| ^~~~
a.cc:39:17: error: request for member 'pos' in 'a', which is of non-class type 'int'
39 | d[a.pos][a.state]=a.cost;
| ^~~
a.cc:39:24: error: request for member 'state' in 'a', which is of non-class type 'int'
39 | d[a.pos][a.state]=a.cost;
| ^~~~~
a.cc:39:33: error: request for member 'cost' in 'a', which is of non-class type 'int'
39 | d[a.pos][a.state]=a.cost;
| ^~~~
a.cc:41:31: error: request for member 'pos' in 'a', which is of non-class type 'int'
41 | for(int i=0;i<g[a.pos].size();i++){
| ^~~
a.cc:42:29: error: request for member 'pos' in 'a', which is of non-class type 'int'
42 | edge &e=g[a.pos][i];
| ^~~
a.cc:44:27: error: request for member 'state' in 'a', which is of non-class type 'int'
44 | if((a.state>>j)&1)continue;
| ^~~~~
a.cc:45:23: error: request for member 'push' in 'Q', which is of non-class type 'int'
45 | Q.push((data){e.to,a.state|(1<<j),a.cost+(double)e.cost/t[j]});
| ^~~~
a.cc:45:29: error: reference to 'data' is ambiguous
45 | Q.push((data){e.to,a.state|(1<<j),a.cost+(double)e.cost/t[j]});
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'struct data'
7 | struct data{
| ^~~~
|
s779810028 | p00719 | C++ | #include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
struct edge{int to,cost;};
struct data{
int pos,state;
double cost;
bool operator>(const data &d)const{
return cost>d.cost;
}
};
vector<edge>g[32];
const double INF=1e9+7;
double d[32][1024];
int t[16];
int n,m,p,a,b;
int main(){
while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b),n||m||p||a||b){
a--;b--;
for(int i=0;i<m;i++){
g[i].clear();
}
fill_n(dp[0],32*1024,INF);
for(int i=0;i<n;i++)scanf("%d",&t[i]);
for(int i=0;i<p;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
x--;y--;
g[x].push_back((edge){y,z});
g[y].push_back((edge){x,z});
}
priority_queue<data,vector<data>,greater<data> >Q;
Q.push((data){a,0,0});
while(Q.size()){
data a=Q.top();Q.pop();
if(d[a.pos][a.state]<a.cost)continue;
d[a.pos][a.state]=a.cost;
for(int i=0;i<g[a.pos].size();i++){
edge &e=g[a.pos][i];
for(int j=0;j<n;j++){
if((a.state>>j)&1)continue;
Q.push((data){e.to,a.state|(1<<j),a.cost+(double)e.cost/t[j]});
}
}
}
double mi=INF;
for(int i=0;i<(1<<n);i++){
mi=min(mi,d[b][i]);
}
if(mi==INF)puts("Impossible");
else printf("%.6f\n",mi);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:25:16: error: 'dp' was not declared in this scope; did you mean 'p'?
25 | fill_n(dp[0],32*1024,INF);
| ^~
| p
a.cc:34:40: error: template argument 1 is invalid
34 | priority_queue<data,vector<data>,greater<data> >Q;
| ^
a.cc:34:40: error: template argument 2 is invalid
a.cc:34:54: error: template argument 1 is invalid
34 | priority_queue<data,vector<data>,greater<data> >Q;
| ^
a.cc:34:56: error: template argument 1 is invalid
34 | priority_queue<data,vector<data>,greater<data> >Q;
| ^
a.cc:34:56: error: template argument 2 is invalid
a.cc:34:56: error: template argument 3 is invalid
a.cc:35:11: error: request for member 'push' in 'Q', which is of non-class type 'int'
35 | Q.push((data){a,0,0});
| ^~~~
a.cc:35:17: error: reference to 'data' is ambiguous
35 | Q.push((data){a,0,0});
| ^~~~
In file included from /usr/include/c++/14/vector:69,
from a.cc:3:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'struct data'
7 | struct data{
| ^~~~
a.cc:36:17: error: request for member 'size' in 'Q', which is of non-class type 'int'
36 | while(Q.size()){
| ^~~~
a.cc:37:13: error: reference to 'data' is ambiguous
37 | data a=Q.top();Q.pop();
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'struct data'
7 | struct data{
| ^~~~
a.cc:37:30: error: request for member 'pop' in 'Q', which is of non-class type 'int'
37 | data a=Q.top();Q.pop();
| ^~~
a.cc:38:20: error: request for member 'pos' in 'a', which is of non-class type 'int'
38 | if(d[a.pos][a.state]<a.cost)continue;
| ^~~
a.cc:38:27: error: request for member 'state' in 'a', which is of non-class type 'int'
38 | if(d[a.pos][a.state]<a.cost)continue;
| ^~~~~
a.cc:38:36: error: request for member 'cost' in 'a', which is of non-class type 'int'
38 | if(d[a.pos][a.state]<a.cost)continue;
| ^~~~
a.cc:39:17: error: request for member 'pos' in 'a', which is of non-class type 'int'
39 | d[a.pos][a.state]=a.cost;
| ^~~
a.cc:39:24: error: request for member 'state' in 'a', which is of non-class type 'int'
39 | d[a.pos][a.state]=a.cost;
| ^~~~~
a.cc:39:33: error: request for member 'cost' in 'a', which is of non-class type 'int'
39 | d[a.pos][a.state]=a.cost;
| ^~~~
a.cc:41:31: error: request for member 'pos' in 'a', which is of non-class type 'int'
41 | for(int i=0;i<g[a.pos].size();i++){
| ^~~
a.cc:42:29: error: request for member 'pos' in 'a', which is of non-class type 'int'
42 | edge &e=g[a.pos][i];
| ^~~
a.cc:44:27: error: request for member 'state' in 'a', which is of non-class type 'int'
44 | if((a.state>>j)&1)continue;
| ^~~~~
a.cc:45:23: error: request for member 'push' in 'Q', which is of non-class type 'int'
45 | Q.push((data){e.to,a.state|(1<<j),a.cost+(double)e.cost/t[j]});
| ^~~~
a.cc:45:29: error: reference to 'data' is ambiguous
45 | Q.push((data){e.to,a.state|(1<<j),a.cost+(double)e.cost/t[j]});
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:7:8: note: 'struct data'
7 | struct data{
| ^~~~
|
s539983756 | p00719 | C++ |
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
public class Main {
int INF = 1 << 28;
//long INF = 1L << 62;
double EPS = 1e-10;
int n, m, p, a, b;
int[] t;
E[] G;
void run() {
Scanner sc = new Scanner(System.in);
for(;;) {
n = sc.nextInt();
m = sc.nextInt();
p = sc.nextInt();
a = sc.nextInt() - 1;
b = sc.nextInt() - 1;
if ((n|m) == 0) break;
t = new int[n];
G = new E[m];
for (int i = 0; i < m; i++) G[i] = new E();
for (int i = 0; i < n; i++) {
t[i] = sc.nextInt();
}
for (int i = 0; i < p; i++) {
int x = sc.nextInt() - 1, y = sc.nextInt() - 1, z = sc.nextInt();
G[x].add(new V(y, z));
G[y].add(new V(x, z));
}
System.out.println(dijkstra());
}
}
String dijkstra() {
double[][] d = new double[1 << n][m];
for (double[] a : d) fill(a, INF);
d[0][a] = 0;
PriorityQueue<S> q = new PriorityQueue<S>();
q.add(new S(0, a, 0));
// debug(q);
for (;!q.isEmpty();) {
S cur = q.remove();
// debug(cur);
if (d[cur.s][cur.p] != cur.d) continue;
if (cur.p == b) return "" + cur.d;
for (V v : G[cur.p]) {
for (int i = 0; i < n; i++) if (((cur.s>>i)&1) == 0) {
if (d[cur.s|(1<<i)][v.t] > cur.d + 1.0 * v.c / t[i]) {
d[cur.s|(1<<i)][v.t] = cur.d + 1.0 * v.c / t[i];
q.add(new S(cur.s|(1<<i), v.t, d[cur.s|(1<<i)][v.t]));
}
}
}
}
return "Impossible";
}
class E extends ArrayList<V>{}
class V {
int t, c;
V(int t, int c) {
this.t = t;
this.c = c;
}
}
class S implements Comparable<S>{
int s, p;
double d;
S(int s, int p, double d) {
this.s = s;
this.p = p;
this.d = d;
}
@Override
public int compareTo(S o) {
// TODO ティツ?ェテ・ツ仰陛ァツ板淌ヲツ按静」ツ?陛」ツつ古」ツ?淌」ツδ。テ」ツつステ」ツδε」ツδ嘉」ツδサテ」ツつケテ」ツつソテ」ツδ?
return d - o.d > EPS ? 1 : -1;
}
public String toString() {
return "[" + Integer.toString(s, 2) + ", " + p + ", " + d + "]";
}
}
void debug(Object... os) {
System.err.println(Arrays.deepToString(os));
}
public static void main(String[] args) {
new Main().run();
}
} | a.cc:89:17: error: stray '@' in program
89 | @Override
| ^
a.cc:2:1: error: 'import' does not name a type
2 | import java.util.*;
| ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
3 | import java.io.*;
| ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
4 | import static java.util.Arrays.*;
| ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
5 | import static java.util.Collections.*;
| ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
6 | import static java.lang.Math.*;
| ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: expected unqualified-id before 'public'
8 | public class Main {
| ^~~~~~
|
s233376438 | p00719 | C++ | #include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
typedef long long ll;
struct Edge {
int to; double cost;
};
const double INF = 1<<29;
int main()
{
while (1) {
int n, m, p, a, b; cin >> n >> m >> p >> a >> b;
a--, b--;
if (!n) break;
vector<int> t(n);
loop (n, i) cin >> t[i];
vector<vector<Edge>> G(m);
loop (p, i) {
int x, y; double z; cin >> x >> y >> z;
x--, y--;
G[x].push_back({ y, z });
G[y].push_back({ x, z });
}
// dp[i][j]: i縺ョ鬥ャ霆雁虻繧剃スソ縺」縺ヲj縺ォ陦後¥譛?ー上さ繧ケ繝? double dp[300][31] = {};
fill(dp[0], dp[299]+31, INF);
dp[0][a] = 0;
// 鬥ャ霆雁虻縺ョ譫壽焚
loop (n, i) {
// 菴ソ縺?ヲャ霆雁虻縺ョ遞ョ鬘? loop (1<<n, crr) if (__builtin_popcount(crr) == i) {
loop (n, k) {
int nxt = crr | (1<<k);
if (nxt == crr) continue;
loop (m, from) {
for (auto e : G[from]) {
dp[nxt][e.to] = min(
dp[nxt][e.to],
dp[crr][from] + e.cost / t[k]
);
}
}
}
}
}
double ans = INF;
loop (300, i) ans = min(ans, dp[i][b]);
if (ans == INF) cout << "Impossible" << endl;
else cout << setprecision(8) << fixed << ans << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:34:14: error: 'dp' was not declared in this scope; did you mean 'p'?
34 | fill(dp[0], dp[299]+31, INF);
| ^~
| p
a.cc:40:31: error: 'crr' was not declared in this scope
40 | int nxt = crr | (1<<k);
| ^~~
a.cc:55:38: error: 'dp' was not declared in this scope; did you mean 'dup'?
55 | loop (300, i) ans = min(ans, dp[i][b]);
| ^~
| dup
a.cc:55:44: error: 'b' was not declared in this scope
55 | loop (300, i) ans = min(ans, dp[i][b]);
| ^
a.cc: At global scope:
a.cc:59:5: error: expected unqualified-id before 'return'
59 | return 0;
| ^~~~~~
a.cc:60:1: error: expected declaration before '}' token
60 | }
| ^
|
s702108008 | p00719 | C++ | #include <iostream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
struct Edge
{
int v, c;
Edge() {}
Edge(int _v, int _c) : v(_v), c(_c) {}
};
using G = vector<vector<Edge>>;
using P = pair<double, pair<int, int>>;
double dijkstra(G& g, vector<int>& t, int a, int b) {
priority_queue<P> que;
// vector<double> d(g.size(), INT32_MAX);
vector<vector<double>> d(g.size(), vector<double>(1 << 8, INT32_MAX));
d[a][0] = 0.0;
que.push(make_pair(0.0, make_pair(a, 0)));
while (!que.empty()) {
auto P = que.top(); que.pop();
int v = P.second.first;
int ti = P.second.second;
double dist = -P.first;
if (dist > d[v][ti]) { continue; }
for (auto e : g[v]) {
for(int i = 0; i < t.size(); ++i) {
if(ti & 1 << i) { continue; }
if(d[e.v][ti | 1 << i] > d[v][ti] + (double)e.c / t[i]) {
d[e.v][ti | 1 << i] = d[v][ti] + (double)e.c / t[i];
que.push(make_pair(-d[e.v][ti | 1 << i], make_pair(e.v, ti | 1 << i)));
}
}
// if (ti >= t.size() - 1) { continue; }
// if (d[e.v][ti + 1] > d[v][ti] + (double)e.c / t[ti + 1]) {
// d[e.v][ti + 1] = d[v][ti] + (double)e.c / t[ti + 1];
// que.push(make_pair(-d[e.v][ti + 1], make_pair(e.v, ti + 1)));
// }
}
}
return *min_element(d[b].begin(), d[b].end());
}
int main()
{
int n, m, p, a, b;
cin >> n >> m >> p >> a >> b;
--a; --b;
vector<int> t(n);
for (auto&& ti : t) {
cin >> ti;
}
G g(m);
for (int i = 0; i < p; ++i) {
int x, y, z;
cin >> x >> y >> z;
--x; --y;
g[x].emplace_back(y, z);
g[y].emplace_back(x, z);
}
double ans = dijkstra(g, t, a, b);
if(ans == INT32_MAX) {
printf("Impossible\n");
} else {
printf("%.3f\n", ans);
}
return 0;
} | a.cc: In function 'double dijkstra(G&, std::vector<int>&, int, int)':
a.cc:21:67: error: 'INT32_MAX' was not declared in this scope
21 | vector<vector<double>> d(g.size(), vector<double>(1 << 8, INT32_MAX));
| ^~~~~~~~~
a.cc:5:1: note: 'INT32_MAX' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
4 | #include <climits>
+++ |+#include <cstdint>
5 |
a.cc:53:17: error: 'min_element' was not declared in this scope
53 | return *min_element(d[b].begin(), d[b].end());
| ^~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:80:19: error: 'INT32_MAX' was not declared in this scope
80 | if(ans == INT32_MAX) {
| ^~~~~~~~~
a.cc:80:19: note: 'INT32_MAX' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
|
s831423146 | p00719 | C++ | #include <cstdio>
#define rep(i,a,n) for(int i=a; i<n; i++)
using namespace std;
const int SIZE = 1 << 10;
const int MAXV = 40;
const int MAXN = 10;
const double INF = 1e9;
int N, M, P, A, B;
double t[MAXN], dist[MAXV][MAXV];
double dp[SIZE][MAXV];
int main() {
while(~scanf("%d%d%d%d%d", &N, &M, &P, &A, &B)) {
A--; B--;
rep(i,0,N) scanf("%lf", &t[i]);
rep(i,0,MAXV) rep(j,0,MAXV) dist[i][j] = INF;
rep(i,0,P) {
int x, y, z; scanf("%d%d%d", &x, &y, &z);
x--; y--;
dist[x][y] = z;
dist[y][x] = z;
}
double ans = INF;
rep(i,0,SIZE) rep(j,0,MAXV) dp[i][j] = INF;
dp[0][A] = 0;
rep(bit,0,1<<N) {
rep(j,0,M) {
rep(to,0,M) {
if(j == to) continue;
rep(i,0,N) {
if(bit >> i & 1) continue;
if(dist[j][to] == INF) continue;
int nbit = bit | (1 << i);
double cost = dist[j][to] / t[i];
dp[nbit][to] = min(dp[nbit][to], dp[bit][j] + cost);
}
}
if(j == B) ans = min(ans, dp[bit][j]);
}
}
if(ans != INF) printf("%.6f\n", ans);
else printf("Impossible\n");
}
return 0;
} | a.cc: In function 'int main()':
a.cc:38:40: error: 'min' was not declared in this scope; did you mean 'main'?
38 | dp[nbit][to] = min(dp[nbit][to], dp[bit][j] + cost);
| ^~~
| main
a.cc:41:34: error: 'min' was not declared in this scope; did you mean 'main'?
41 | if(j == B) ans = min(ans, dp[bit][j]);
| ^~~
| main
|
s409557553 | p00719 | C++ | #include <iostream>
#include <tuple>
#include <set>
#include <vector>
#include <deque>
typedef std::tuple<int, int, double> T;
std::vector<T> dis_city;
std::deque<double> dis;
std::vector<int> flag;
std::vector<int> num_basya;
int n, m, p, a, b;
double search(int ima)
{
if ( num_basya.size() < dis.size() ) {
return 0xffff;
}
if ( ima == b - 1 ) {
double sum = 0;
std::deque<double> d = dis;
std::sort(d.begin(), d.end());
int j = d.size() - 1;
for ( int i = num_basya.size() - 1; i >= 0; --i ) {
sum += d[j] / num_basya[i];
//std::cout << "d:" << d[j] << " basya:" << num_basya[i] << " sum:" << sum << std::endl;
j--;
if ( j < 0 ) break;
}
return sum;
}
double ans = 0xffff;
for ( int i = 0; i < dis_city.size(); ++i ) {
if ( std::get<0>(dis_city[i]) == ima ) {
if ( flag[std::get<1>(dis_city[i])] == false ) {
flag[std::get<1>(dis_city[i])] = true;
dis.push_back(std::get<2>(dis_city[i]));
//std::cout << std::get<0>(dis_city[i]) << " -> " << std::get<1>(dis_city[i]) << std::endl;
double tmp = search(std::get<1>(dis_city[i]));
if ( ans > tmp ) ans = tmp;
dis.pop_back();
flag[std::get<1>(dis_city[i])] = false;
}
}
}
return ans;
}
int main(void)
{
while(true) {
dis_city.clear(); dis.clear(); flag.clear(); num_basya.clear();
std::cin >> n >> m >> p >> a >> b;
if ( n == 0 && m == 0 ) return 0;
flag.resize(m);
for ( int i = 0; i < m; ++i ) flag[i] = false;
num_basya.resize(n);
for ( auto &v: num_basya ) {
std::cin >> v;
}
std::sort(num_basya.begin(), num_basya.end());
for ( int i = 0; i < p; ++i ) {
int x, y, z;
std::cin >> x;
std::cin >> y;
std::cin >> z;
x--; y--;
T t1(x,y,z), t2(y,x,z);
dis_city.push_back(t1);
dis_city.push_back(t2);
}
flag[a - 1] = true;
double ans = search(a - 1);
if ( ans > 65530 ) {
std::cout << "Impossible" << std::endl;
} else {
printf("%.4f\n", ans);
}
}
return 0;
} | a.cc: In function 'double search(int)':
a.cc:23:22: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
23 | std::sort(d.begin(), d.end());
| ^~~~
| qsort
a.cc: In function 'int main()':
a.cc:65:22: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
65 | std::sort(num_basya.begin(), num_basya.end());
| ^~~~
| qsort
|
s058323278 | p00719 | C++ | #include <iostream>
#include <tuple>
#include <set>
#include <vector>
#include <deque>
typedef std::tuple<int, int, double> T;
std::vector<T> dis_city;
std::deque<double> dis;
std::vector<int> flag;
std::vector<int> num_basya;
int n, m, p, a, b;
double cost[2][2][2][2][2][2][2][2][30][30];
std::vector<std::tuple<int,int>> table;
/*double search(int ima)
{
if ( num_basya.size() < dis.size() ) {
return 0xffff;
}
if ( ima == b - 1 ) {
double sum = 0;
std::deque<double> d = dis;
std::sort(d.begin(), d.end());
int j = d.size() - 1;
for ( int i = num_basya.size() - 1; i >= 0; --i ) {
sum += d[j] / num_basya[i];
//std::cout << "d:" << d[j] << " basya:" << num_basya[i] << " sum:" << sum << std::endl;
j--;
if ( j < 0 ) break;
}
return sum;
}
double ans = 0xffff;
for ( int i = 0; i < dis_city.size(); ++i ) {
if ( std::get<0>(dis_city[i]) == ima ) {
if ( flag[std::get<1>(dis_city[i])] == false ) {
flag[std::get<1>(dis_city[i])] = true;
dis.push_back(std::get<2>(dis_city[i]));
//std::cout << std::get<0>(dis_city[i]) << " -> " << std::get<1>(dis_city[i]) << std::endl;
double tmp = search(std::get<1>(dis_city[i]));
if ( ans > tmp ) ans = tmp;
dis.pop_back();
flag[std::get<1>(dis_city[i])] = false;
}
}
}
return ans;
}*/
long long unsigned PopCount(long long unsigned x) {
x = (x & 0x5555555555555555ULL) + ((x & 0xAAAAAAAAAAAAAAAAULL) >> 1);
x = (x & 0x3333333333333333ULL) + ((x & 0xCCCCCCCCCCCCCCCCULL) >> 2);
x = (x & 0x0F0F0F0F0F0F0F0FULL) + ((x & 0xF0F0F0F0F0F0F0F0ULL) >> 4);
x *= 0x0101010101010101ULL;
return x;
}
double& acost(int i, int j, int k)
{
return cost[i&1][(i&2)>>1][(i&4)>>2][(i&8)>>3][(i&16)>>4][(i&32)>>5][(i&64)>>6][(i&128)>>7][j][k];
}
double search()
{
for ( int i = 0; i < (1<<n); ++i ) {
for ( int j = 0; j < m; ++j ) {
for ( int k = 0; k < m; ++k ) {
if ( i == 0 && j == k ) {
acost(i, j, k) = 0;
} else {
acost(i, j, k) = 0xffff;
}
}
}
}
for ( int i = 0; i < (1<<n); ++i ) {
int q = std::get<1>(table[i]);
for ( int l = 0; l < n; l++) {
if ( q & (1<<l) ) {
for ( int j = 0; j < m; ++j ) {
for ( int k = 0; k < m; ++k ) {
for ( int o = 0; o < dis_city.size(); ++o ) {
if ( std::get<0>(dis_city[o]) == k ) {
double c = acost(q^(1<<l),j,std::get<1>(dis_city[o])) + std::get<2>(dis_city[o])/num_basya[l];
acost(q, j, k) = (acost(q,j,k) < (c)) ? acost(q,j,k) : c;
}
}
}
}
}
}
}
double ans = 0xffff;
for ( int i = 1; i < (1<<n); ++i ) {
if ( ans > acost(i, a-1, b-1) ) {
ans = acost(i, a-1, b-1);
}
}
return ans;
}
int main(void)
{
while(true) {
dis_city.clear(); dis.clear(); flag.clear(); num_basya.clear();
std::cin >> n >> m >> p >> a >> b;
if ( n == 0 && m == 0 ) return 0;
flag.resize(m);
for ( int i = 0; i < m; ++i ) flag[i] = false;
num_basya.resize(n);
for ( auto &v: num_basya ) {
std::cin >> v;
}
std::sort(num_basya.begin(), num_basya.end());
for ( int i = 0; i < p; ++i ) {
int x, y, z;
std::cin >> x;
std::cin >> y;
std::cin >> z;
x--; y--;
T t1(x,y,z), t2(y,x,z);
dis_city.push_back(t1);
dis_city.push_back(t2);
}
flag[a - 1] = true;
table.resize(1<<n);
for ( int i = 0; i < (1<<n); ++i ) table[i] = std::make_tuple(PopCount(i), i);
std::sort(table.begin(), table.end());
double ans = search();
if ( ans > 65530 ) {
std::cout << "Impossible" << std::endl;
} else {
printf("%.4f\n", ans);
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:125:22: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
125 | std::sort(num_basya.begin(), num_basya.end());
| ^~~~
| qsort
a.cc:143:22: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
143 | std::sort(table.begin(), table.end());
| ^~~~
| qsort
|
s850907904 | p00719 | C++ | #include <assert.h>
#include <algorithm>
#include <complex>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const double INF = 100000000;
using namespace std;
//i???????????????????????????
bool getBit(int num, int i){
return ((num & (1 << i)) != 0);
}
//i?????????1?????????
int setBit(int num, int i){
return num | (1 << i);
}
//i?????????0?????????
int clearBit(int num, int i){
int mask = ~(1 << i);
return num & mask;
}
//i?????????v??§???????????????
int updateBit(int num, int i, int v){
int mask = ~(1 << i);
return (num & mask) | (v << i);
}
int main(){
int n, m, p, a, b;
while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b), n){
a--; b--;
double g[40][40];
rep(i,40) memset(g[i],-1,sizeof(g[i]));
double t[10];
rep(i,n) scanf("%lf",&t[i]);
rep(i,p){
int a, b;
double c;
scanf("%d%d%lf",&a,&b,&c);
a--; b--;
g[a][b] = g[b][a] = c;
}
double dp[500][40];
rep(i, 1 << n) rep(j, 40) dp[i][j] = INF;
dp[(1 << n) - 1][a] = 0;
double ans = INF;
for(int s = (1 << n) - 1; s >= 0; s--){
ans = min(ans, dp[s][b]);
rep(i,n){
if(getBit(s,i)){
rep(v,m){
rep(u,m){
if(g[v][u] == -1) continue;
dp[clearBit(s,i)][u] = min(dp[clearBit(s,i)][u], dp[s][v] + g[v][u] / t[i]);
}
}
}
}
}
if(ans == INF){
printf("Impossible\n");
}else{
printf("%.3f\n",ans);
}
}
} | a.cc: In function 'int main()':
a.cc:60:19: error: 'memset' was not declared in this scope
60 | rep(i,40) memset(g[i],-1,sizeof(g[i]));
| ^~~~~~
a.cc:24:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
23 | #include <utility>
+++ |+#include <cstring>
24 | #include <vector>
|
s743768811 | p00719 | C++ | #include <assert.h>
#include <algorithm>
#include <complex>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const double INF = 100000000;
using namespace std;
//i???????????????????????????
bool getBit(int num, int i){
return ((num & (1 << i)) != 0);
}
//i?????????1?????????
int setBit(int num, int i){
return num | (1 << i);
}
//i?????????0?????????
int clearBit(int num, int i){
int mask = ~(1 << i);
return num & mask;
}
//i?????????v??§???????????????
int updateBit(int num, int i, int v){
int mask = ~(1 << i);
return (num & mask) | (v << i);
}
int main(){
int n, m, p, a, b;
while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b), n){
a--; b--;
double g[40][40];
rep(i,40) memset(g[i],-1,sizeof(g[i]));
double t[10];
rep(i,n) scanf("%lf",&t[i]);
rep(i,p){
int a, b;
double c;
scanf("%d%d%lf",&a,&b,&c);
a--; b--;
g[a][b] = g[b][a] = c;
}
double dp[500][40];
rep(i, 1 << n) rep(j, 40) dp[i][j] = INF;
dp[(1 << n) - 1][a] = 0;
double ans = INF;
for(int s = (1 << n) - 1; s >= 0; s--){
ans = min(ans, dp[s][b]);
rep(i,n){
if(getBit(s,i)){
rep(v,m){
rep(u,m){
if(g[v][u] == -1) continue;
dp[clearBit(s,i)][u] = min(dp[clearBit(s,i)][u], dp[s][v] + g[v][u] / t[i]);
}
}
}
}
}
if(ans == INF){
printf("Impossible\n");
}else{
printf("%.3f\n",ans);
}
}
} | a.cc: In function 'int main()':
a.cc:60:19: error: 'memset' was not declared in this scope
60 | rep(i,40) memset(g[i],-1,sizeof(g[i]));
| ^~~~~~
a.cc:24:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
23 | #include <utility>
+++ |+#include <cstring>
24 | #include <vector>
|
s968909625 | p00719 | C++ | #include <iostream>
#include <tuple>
#include <set>
#include <vector>
#include <deque>
#include <queue>
typedef std::tuple<int, int, double> T;
std::vector<T> dis_city;
std::vector<int> num_basya;
int n, m, p, a, b;
std::vector<std::tuple<int,int>> table;
double cost[1<<8][30];
double search()
{
for ( int i = 0; i < (1<<n); ++i ) {
for ( int k = 0; k < m; ++k ) {
cost[i][k] = 0xffff;
}
}
cost[(1<<n)-1][a] = 0;
double ans = 0xffff;
std::priority_queue<std::tuple<double, int, int>> q;
q.push(std::make_tuple(0, a, (1<<n)-1));
while(!q.empty()) {
double c = std::get<0>(q.top());
int from = std::get<1>(q.top());
int s = std::get<2>(q.top());
q.pop();
if ( from == b ) { ans = c; }
for ( int i = 0; i < n; ++i ) {
if ( s & (1<<i) ) {
for ( int j = 0; j < dis_city.size(); ++j ) {
if ( std::get<0>(dis_city[j]) == from ) {
int to = std::get<1>(dis_city[j]);
double f = c + std::get<2>(dis_city[j]) / num_basya[i];
if ( cost[s ^ (1<<i)][to] > f ) {
cost[s ^ (1<<i)][to] = f;
q.push(std::make_tuple(f, to, s ^ (1<<i)));
}
}
}
}
}
}
return ans;
}
int main(void)
{
while(true) {
dis_city.clear(); num_basya.clear();
std::cin >> n >> m >> p >> a >> b;
if ( n == 0 && m == 0 ) return 0;
a--; b--;
num_basya.resize(n);
for ( auto &v: num_basya ) {
std::cin >> v;
}
std::sort(num_basya.begin(), num_basya.end());
for ( int i = 0; i < p; ++i ) {
int x, y, z;
std::cin >> x;
std::cin >> y;
std::cin >> z;
x--; y--;
T t1(x,y,z), t2(y,x,z);
dis_city.push_back(t1);
dis_city.push_back(t2);
}
double ans = search();
if ( ans > 65530 ) {
std::cout << "Impossible" << std::endl;
} else {
printf("%.4f\n", ans);
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:68:22: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
68 | std::sort(num_basya.begin(), num_basya.end());
| ^~~~
| qsort
|
s376341700 | p00719 | C++ | #include <iostream>
#include <tuple>
#include <set>
#include <vector>
#include <deque>
#include <queue>
typedef std::tuple<int, int, double> T;
std::vector<T> dis_city;
std::vector<int> num_basya;
int n, m, p, a, b;
std::vector<std::tuple<int,int>> table;
double cost[1<<8][30];
double search()
{
for ( int i = 0; i < (1<<n); ++i ) {
for ( int k = 0; k < m; ++k ) {
cost[i][k] = 0xffff;
}
}
cost[(1<<n)-1][a] = 0;
double ans = 0xffff;
std::priority_queue<std::tuple<double, int, int>> q;
q.push(std::make_tuple(0, a, (1<<n)-1));
while(!q.empty()) {
double c = std::get<0>(q.top());
int from = std::get<1>(q.top());
int s = std::get<2>(q.top());
q.pop();
if ( from == b ) { ans = c; }
for ( int i = 0; i < n; ++i ) {
if ( s & (1<<i) ) {
for ( int j = 0; j < dis_city.size(); ++j ) {
if ( std::get<0>(dis_city[j]) == from ) {
int to = std::get<1>(dis_city[j]);
double f = c + std::get<2>(dis_city[j]) / num_basya[i];
if ( cost[s ^ (1<<i)][to] > f ) {
cost[s ^ (1<<i)][to] = f;
q.push(std::make_tuple(f, to, s ^ (1<<i)));
}
}
}
}
}
}
return ans;
}
int main(void)
{
while(true) {
dis_city.clear(); num_basya.clear();
std::cin >> n >> m >> p >> a >> b;
if ( n == 0 && m == 0 ) return 0;
a--; b--;
num_basya.resize(n);
for ( auto &v: num_basya ) {
std::cin >> v;
}
std::sort(num_basya.begin(), num_basya.end());
for ( int i = 0; i < p; ++i ) {
int x, y, z;
std::cin >> x;
std::cin >> y;
std::cin >> z;
x--; y--;
T t1(x,y,z), t2(y,x,z);
dis_city.push_back(t1);
dis_city.push_back(t2);
}
double ans = search();
if ( ans > 65530 ) {
std::cout << "Impossible" << std::endl;
} else {
printf("%.4f\n", ans);
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:68:22: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
68 | std::sort(num_basya.begin(), num_basya.end());
| ^~~~
| qsort
|
s682996560 | p00719 | C++ | #define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;
/*---------------------------------------------------*/
typedef pair<double,pair<int,int> > type;
void solve(int n,int m,int p,int a,int b){
a--;b--;
vector<int> t(m);
for(int i=0;i<n;i++){
cin>>t[i];
}
int dist[30][30];
for(int i=0;i<30;i++){
for(int j=0;j<30;j++)dist[i][j]=-1;
}
vector<int> x(p),y(p),z(p);
for(int i=0;i<p;i++){
cin>>x[i]>>y[i]>>z[i];
x[i]--;y[i]--;
dist[x[i]][y[i]]=dist[y[i]][x[i]]=z[i];
}
double dp[30][1<<8];
for(int i=0;i<30;i++){
for(int j=0;j<(1<<8);j++)dp[i][j]=1e12;
}
dp[a][0]=0;
// first -> コスト | second.first -> 現在地 second.second -> bit mask
priority_queue<type,vector<type>,greater<type> > que;
que.push(mp(0,mp(a,0)));
while(que.size()){
type top=que.top();que.pop();
double cost=top.first;
int now=top.second.first,now_mask=top.second.second;
if(cost>dp[now][now_mask])continue;
for(int i=0;i<m;i++)if(dist[now][i]!=-1){
for(int j=0;j<n;j++){
int next_mask=now_mask;
if(next_mask & (1<<j))continue;
next_mask|=(1<<j);
double next_cost=cost+double(dist[now][i])/t[j];;
if(dp[i][next_mask]>next_cost){
dp[i][next_mask]=next_cost;
que.push(mp(next_cost,mp(i,next_mask)));
}
}
}
}
double ans=1e12;
for(int i=0;i<(1<<8);i++){
ans=min(ans,dp[b][i]);
}
if(ans==1e12)cout<<"Impossible"<<endl;
else cout<<ans<<endl;
}
int main(){
int n,m,p,a,b;
while(cin>>n>>m>>p>>a>>b){
if(!(n|m|p|a|b))break;
solve(n,m,p,a,b);
}
return 0;
}
| a.cc:11:9: error: 'vector' does not name a type
11 | typedef vector<int> vi;
| ^~~~~~
a.cc:12:9: error: 'vector' does not name a type
12 | typedef vector<long long>vll;
| ^~~~~~
a.cc:13:9: error: 'pair' does not name a type
13 | typedef pair<int,int> pi;
| ^~~~
a.cc:22:9: error: 'pair' does not name a type
22 | typedef pair<double,pair<int,int> > type;
| ^~~~
a.cc: In function 'void solve(int, int, int, int, int)':
a.cc:26:3: error: 'vector' was not declared in this scope
26 | vector<int> t(m);
| ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
+++ |+#include <vector>
1 | #define rrep(i,n) for(int i=n-1;i>=0;i--)
a.cc:26:10: error: expected primary-expression before 'int'
26 | vector<int> t(m);
| ^~~
a.cc:28:5: error: 'cin' was not declared in this scope
28 | cin>>t[i];
| ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
+++ |+#include <iostream>
1 | #define rrep(i,n) for(int i=n-1;i>=0;i--)
a.cc:28:10: error: 't' was not declared in this scope
28 | cin>>t[i];
| ^
a.cc:36:10: error: expected primary-expression before 'int'
36 | vector<int> x(p),y(p),z(p);
| ^~~
a.cc:38:5: error: 'cin' was not declared in this scope
38 | cin>>x[i]>>y[i]>>z[i];
| ^~~
a.cc:38:5: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:38:10: error: 'x' was not declared in this scope
38 | cin>>x[i]>>y[i]>>z[i];
| ^
a.cc:38:16: error: 'y' was not declared in this scope
38 | cin>>x[i]>>y[i]>>z[i];
| ^
a.cc:38:22: error: 'z' was not declared in this scope
38 | cin>>x[i]>>y[i]>>z[i];
| ^
a.cc:50:3: error: 'priority_queue' was not declared in this scope
50 | priority_queue<type,vector<type>,greater<type> > que;
| ^~~~~~~~~~~~~~
a.cc:1:1: note: 'std::priority_queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
+++ |+#include <queue>
1 | #define rrep(i,n) for(int i=n-1;i>=0;i--)
a.cc:50:18: error: 'type' was not declared in this scope; did you mean 'typeof'?
50 | priority_queue<type,vector<type>,greater<type> > que;
| ^~~~
| typeof
a.cc:50:35: error: expected primary-expression before ',' token
50 | priority_queue<type,vector<type>,greater<type> > que;
| ^
a.cc:50:36: error: 'greater' was not declared in this scope
50 | priority_queue<type,vector<type>,greater<type> > que;
| ^~~~~~~
a.cc:50:50: error: expected primary-expression before '>' token
50 | priority_queue<type,vector<type>,greater<type> > que;
| ^
a.cc:50:52: error: 'que' was not declared in this scope
50 | priority_queue<type,vector<type>,greater<type> > que;
| ^~~
a.cc:5:12: error: 'make_pair' was not declared in this scope
5 | #define mp make_pair
| ^~~~~~~~~
a.cc:51:17: note: in expansion of macro 'mp'
51 | que.push(mp(0,mp(a,0)));
| ^~
a.cc:1:1: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
+++ |+#include <utility>
1 | #define rrep(i,n) for(int i=n-1;i>=0;i--)
a.cc:5:12: error: 'make_pair' was not declared in this scope
5 | #define mp make_pair
| ^~~~~~~~~
a.cc:51:12: note: in expansion of macro 'mp'
51 | que.push(mp(0,mp(a,0)));
| ^~
a.cc:5:12: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
5 | #define mp make_pair
| ^~~~~~~~~
a.cc:51:12: note: in expansion of macro 'mp'
51 | que.push(mp(0,mp(a,0)));
| ^~
a.cc:53:9: error: expected ';' before 'top'
53 | type top=que.top();que.pop();
| ^~~~
| ;
a.cc:54:17: error: 'top' was not declared in this scope
54 | double cost=top.first;
| ^~~
a.cc:56:21: error: 'now_mask' was not declared in this scope
56 | if(cost>dp[now][now_mask])continue;
| ^~~~~~~~
a.cc:59:25: error: 'now_mask' was not declared in this scope; did you mean 'next_mask'?
59 | int next_mask=now_mask;
| ^~~~~~~~
| next_mask
a.cc:62:54: error: 't' was not declared in this scope
62 | double next_cost=cost+double(dist[now][i])/t[j];;
| ^
a.cc:72:9: error: 'min' was not declared in this scope
72 | ans=min(ans,dp[b][i]);
| ^~~
a.cc:74:16: error: 'cout' was not declared in this scope
74 | if(ans==1e12)cout<<"Impossible"<<endl;
| ^~~~
a.cc:74:16: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:74:36: error: 'endl' was not declared in this scope
74 | if(ans==1e12)cout<<"Impossible"<<endl;
| ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
+++ |+#include <ostream>
1 | #define rrep(i,n) for(int i=n-1;i>=0;i--)
a.cc:75:8: error: 'cout' was not declared in this scope
75 | else cout<<ans<<endl;
| ^~~~
a.cc:75:8: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:75:19: error: 'endl' was not declared in this scope
75 | else cout<<ans<<endl;
| ^~~~
a.cc:75:19: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc: In function 'int main()':
a.cc:80:9: error: 'cin' was not declared in this scope
80 | while(cin>>n>>m>>p>>a>>b){
| ^~~
a.cc:80:9: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
|
s163270460 | p00719 | C++ | #include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;
const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);
struct Stage {
Stage(int n_, int m_, int p_, int a_, int b_):
n(n_),
m(m_),
p(p_),
a(a_),
b(b_)
{
t.resize(n);
edge.resize(m);
REP(i, n) {
int tmp;
cin >> tmp;
t[i] = tmp;
}
REP(i, p) {
int x, y, z;
cin >> x >> y >> z;
x--; y--;
edge[x].push_back({ y,z });
edge[y].push_back({ x,z });
}
}
void action()
{
double res = INF;
sort(t.begin(), t.end());
do {
/*
{
double tmp = search_route(t);
if (res > tmp) {
cerr << "updated:" << endl;
debug(t);
cerr << "ans:" << tmp << endl << endl;
}
}
*/
res = min(res, search_route(t));
} while (next_permutation(t.begin(), t.end()));
//cerr << "answer is:::: ";
cout << (is_reach(res)
? to_string(res)
: "Impossible" )
<< endl;
}
private:
const int n, m, p, a, b;
vector<int> t;
vector<vector<pair<int, int>>> edge;
bool is_reach(double res) {
return res < INF / 2.;
}
double search_route(vector<int> t)
{
queue<int> now, will;
unique_ptr<double[]> time(new double[m]), willTime(new double[m]);
REP(i, m) {
time[i] = willTime[i] = INF;
}
time[a] = 0;
willTime[a] = 0;
now.push(a);
//チケットを順番に使う。
for (int ticket : t)
{
//消費対象は、辿り着いた土地に対して
while (!now.empty())
{
int here = now.front(); now.pop();
//消費する
for (auto route : edge[here])
{
int next = route.first;
int dist = route.second;
double additional = 1.*dist / ticket;
if (willTime[next] >= time[here] + additional)
{
willTime[next] = time[here] + additional;
will.push(next);
}
}
}
now.swap(will);
REP(i, m) {
time[i] = willTime[i];
}
}
return time[b];
}
void debug(vector<int> v)
{
for (auto num : v)cerr << num << " ";
cerr << endl;
}
};
//デバッグ
void debug()
{
int N;
cin>>N;
}
//メイン関数
int main()
{
while (true)
{
int n, m, p, a, b;
cin >> n >> m >> p >> a >> b;
if (n == 0)break;
a--; b--;
Stage stage(n, m, p, a, b);
stage.action();
}
//debug();
return 0;
}
| a.cc: In member function 'double Stage::search_route(std::vector<int>)':
a.cc:88:17: error: 'unique_ptr' was not declared in this scope
88 | unique_ptr<double[]> time(new double[m]), willTime(new double[m]);
| ^~~~~~~~~~
a.cc:13:1: note: 'std::unique_ptr' is defined in header '<memory>'; this is probably fixable by adding '#include <memory>'
12 | #include<fstream>
+++ |+#include <memory>
13 |
a.cc:88:28: error: expected primary-expression before 'double'
88 | unique_ptr<double[]> time(new double[m]), willTime(new double[m]);
| ^~~~~~
a.cc:90:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
90 | time[i] = willTime[i] = INF;
| ^
a.cc:90:35: error: 'willTime' was not declared in this scope
90 | time[i] = willTime[i] = INF;
| ^~~~~~~~
a.cc:92:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
92 | time[a] = 0;
| ^
a.cc:92:25: error: assignment of read-only location '*(time + ((sizetype)((Stage*)this)->Stage::a))'
92 | time[a] = 0;
| ~~~~~~~~^~~
a.cc:93:17: error: 'willTime' was not declared in this scope
93 | willTime[a] = 0;
| ^~~~~~~~
a.cc:109:72: warning: pointer to a function used in arithmetic [-Wpointer-arith]
109 | if (willTime[next] >= time[here] + additional)
| ^
a.cc:109:74: error: invalid operands of types 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'} and 'double' to binary 'operator+'
109 | if (willTime[next] >= time[here] + additional)
| ~~~~~~~~~~ ^ ~~~~~~~~~~
| | |
| | double
| time_t(time_t*) noexcept {aka long int(long int*) noexcept}
a.cc:111:75: warning: pointer to a function used in arithmetic [-Wpointer-arith]
111 | willTime[next] = time[here] + additional;
| ^
a.cc:111:77: error: invalid operands of types 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'} and 'double' to binary 'operator+'
111 | willTime[next] = time[here] + additional;
| ~~~~~~~~~~ ^ ~~~~~~~~~~
| | |
| | double
| time_t(time_t*) noexcept {aka long int(long int*) noexcept}
a.cc:118:39: warning: pointer to a function used in arithmetic [-Wpointer-arith]
118 | time[i] = willTime[i];
| ^
a.cc:122:30: warning: pointer to a function used in arithmetic [-Wpointer-arith]
122 | return time[b];
| ^
a.cc:122:30: error: cannot convert 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'double' in return
122 | return time[b];
| ^
| |
| time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
|
s937401850 | p00719 | C++ | //1444
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned uint;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
struct edge{
int fr;
int to;
double d;
int j;
edge(int f,int t,double d0,int j0){
fr=f;
to=t;
d=d0;
j=j0;
}
};
struct cmp{
bool operator()(edge a,edge b){
return a.d>b.d;
}
};
int main(){
int n,m,p,a,b;
while(cin >> n >> m >> p >> a >> b){
a--;
b--;
if(n==0) break;
vector<vector<edge> > g(m);
vint baken(n);
for(int i=0;i<n;i++) cin >> baken[i];
for(int i=0;i<p;i++){
edge e(0,0,0,0);
cin >> e.fr >> e.to >> e.d;
e.fr--;
e.to--;
g[e.fr].push_back(e);
g[e.to].push_back(edge(e.to,e.fr,e.d,0));
}
int prev[31][1<<9];
priority_queue<edge,vector<edge>,cmp> pq;
memset(prev,-1,sizeof(prev));
edge e(-2,a,0,0);
pq.push(e);
int imp=1;
while(!pq.empty()){
e=pq.top();
// cout << e.fr << " " << e.to << " " << e.d << endl;
pq.pop();
if(prev[e.to][e.j]!=-1) continue;
prev[e.to][e.j]=e.d;
if(e.to==b){
imp=0;
break;
}
for(int i=0;i<g[e.to].size();i++){
for(int j=1,k=0;j<(1<<n);j*=2,k++){
if((e.j&j)==0){
pq.push(edge(e.to,g[e.to][i].to,e.d+((double)g[e.to][i].d/baken[k]),(e.j|j)));
}
}
}
}
if(imp==0){
printf("%.5f\n",e.d);
}else{
printf("Impossible\n");
}
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:66:17: error: 'memset' was not declared in this scope
66 | memset(prev,-1,sizeof(prev));
| ^~~~~~
a.cc:18:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
17 | #include<complex>
+++ |+#include <cstring>
18 |
|
s702546057 | p00719 | C++ | #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int __ch;
int x;
int num(){
x=0;
while(!isdigit(_ch=getchar());
x=_ch-'0';
while(isdigit(_ch=getchar())x=(x<<3)+(x<<1)+_ch-'0';
return x;
}
PI V[30][30];
int Vs[30];
bool vis[1<<8][30];
int ti[30];
int main(){
while(true){
int n=num(),m=num(),p=num(),a=num()-1,b=num()-1;
if(!n)break;
rep(i,n)ti[i]=num();
rep(i,m)Vs[i]=0;
rep(i,p){
int x=num()-1,y=num()-1,z=num();
V[x][Vs[x]++]=mp(y,z);
V[y][Vs[y]++]=mp(x,z);
}
priority_queue<pair<double,PI> > Q;
Q.push(mp(0,mp(a,0)));
memset(vis,0,sizeof(vis));
double ans=-1;
while(!Q.empty()){
int v=Q.top().S.F,cst=Q.top().S.S;
double cc=-Q.top().F;
Q.pop();
if(vis[cst][v])continue;
vis[cst][v]=true;
if(v==b){
ans=cc;
break;
}
rep(i,n){
if(cst>>i&1)continue;
rep(j,Vs[v]){
int nv=V[v][j].first;
int tc=V[v][j].second;
int nst=cst|(1<<i);
if(vis[nst][nv])continue;
double nc=cc+1.0*tc/ti[i];
Q.push(mp(-nc,mp(nv,nst)));
}
}
}
if(ans<0)puts("Impossible");
else printf("%f\n",ans);
}
} | a.cc: In function 'int num()':
a.cc:45:18: error: '_ch' was not declared in this scope; did you mean '__ch'?
45 | while(!isdigit(_ch=getchar());
| ^~~
| __ch
a.cc:45:32: error: expected ')' before ';' token
45 | while(!isdigit(_ch=getchar());
| ~ ^
| )
a.cc:46:5: error: '_ch' was not declared in this scope; did you mean '__ch'?
46 | x=_ch-'0';
| ^~~
| __ch
a.cc:47:31: error: expected ')' before 'x'
47 | while(isdigit(_ch=getchar())x=(x<<3)+(x<<1)+_ch-'0';
| ~ ^
| )
|
s103401110 | p00719 | C++ | #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
typedef struct _state{
int from,vis;
double cost;
_state(double ic,int ifr,int iv):cost(ic),from(ifr),vis(iv){
};
bool operator<(const _state&r)const{
return cost>r.cost;
};
}state;
typedef struct _edge{
int to,cost;
_edge(int ito,int icost):to(ito),cost(icost){
};
}edge;
int ret,c;
char str[300];
int pos;
inline int num(){
ret=0;
while(!isdigit(str[pos]))++pos;
ret=str[pos]&15;
while(isdigit(str[++pos]))ret=(ret<<3)+(ret<<1)+(c&15);
return ret;
}
main(){
int n,m,p,a,b;
while(true){
gets(str);pos=0;
n=num(),m=num(),p=num(),a=num()-1,b=num()-1;
if(!n)break;
int ti[n];
vector<edge> V[m];
gets(str);pos=0;
rep(i,n)ti[i]=num();
rep(i,p){
gets(str);pos=0;
int x=num()-1,y=num()-1,z=num();
V[x].pb(edge(y,z));
V[y].pb(edge(x,z));
}
priority_queue<state> Q;
Q.push(state(0,a,0));
bool cost[1<<n][m];
memset(cost,0,sizeof(cost));
double ans=-1;
int from,cti;
double ccost;
while(!Q.empty()){
from=Q.top().from,cti=Q.top().vis;
ccost=Q.top().cost;
Q.pop();
if(cost[cti][from])continue;
cost[cti][from]=true;
if(from==b){
ans=ccost;
break;
}
int to,cc,sz;
rep(i,n){
if(cti>>i&1)continue;
sz=SZ(V[from]);
rep(j,sz){
to=V[from][j].to;
cc=V[from][j].cost;
if(cost[cti|1<<i][to])continue;
Q.push(state(ccost+1.0*cc/ti[i],to,cti|1<<i));
}
}
}
if(ans<0)puts("Impossible");
else printf("%f\n",ans);
}
} | a.cc:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
68 | main(){
| ^~~~
a.cc: In function 'int main()':
a.cc:71:5: error: 'gets' was not declared in this scope; did you mean 'getw'?
71 | gets(str);pos=0;
| ^~~~
| getw
|
s514125327 | p00719 | C++ | #include<iostream>
#include<queue>
using namespace std;
int n,m,p,a,b;
int t[8];
struct edge{
int x,y,cost;
};
struct state{
int x,nt;
double ncost;
};
bool operator < (state a,state b){
return a.ncost>b.ncost;
}
void solve(){
double ans=1000000;
for(int i=0;i<n;i++){
scanf("%d",&t[i]);
}
edge e[1000];
for(int i=0;i<p;i++){
scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].cost);
e[i+p].x=e[i].y;
e[i+p].y=e[i].x;
e[i+p].cost=e[i].cost;
}
priority_queue<state> Q;
double total[1<<8][31];
bool c[1<<8][31];
memset(total,-1,sizeof(total));
memset(c,0,sizeof(c));
state now;
now.ncost=0.0;
now.x=a;
now.nt=(1<<n)-1;
Q.push(now);
while(!Q.empty()){
state now;
now=Q.top();
Q.pop();
if(c[now.nt][now.x]==true)
continue;
c[now.nt][now.x]=true;
if(now.x==b)
ans=min(ans,now.ncost);
for(int i=0;i<p*2;i++){
if(e[i].x==now.x){
for(int j=0;j<n;j++){
if((now.nt>>j & 1) == 1){
state next;
next.x=e[i].y;
next.nt=(~(1<<j)) & now.nt;
next.ncost=now.ncost+(double)e[i].cost/(double)t[j];
total[next.nt][next.x]=next.ncost;
Q.push(next);
}
}
}
}
}
if(ans>100000)
cout<<"Impossible\n";
else
cout<<ans<<"\n";
}
int main()
{
scanf("%d%d%d%d%d",&n,&m,&p,&a,&b);
while(n!=0){
solve();
scanf("%d%d%d%d%d",&n,&m,&p,&a,&b);
}
return 0;
} | a.cc: In function 'void solve()':
a.cc:38:9: error: 'memset' was not declared in this scope
38 | memset(total,-1,sizeof(total));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<queue>
+++ |+#include <cstring>
3 | using namespace std;
|
s574606034 | p00719 | C++ | #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#define EPS 1e-9
using namespace std;
typedef pair<int,int> P;
typedef pair<double,P> P2;
double d[50][1<<10];
int main(){
int n,m,p,a,b;
int x,y,z;
int t[10];
vector<P> g[50];
while(cin >> n >> m >> p >> a >> b, n||m||p||a||b){
for(int i=0;i<n;i++)cin >> t[i];
for(int i=0;i<=m;i++)g[i].clear();
for(int i=0;i<p;i++){
cin >> x >> y >> z;
g[x].push_back(P(y,z));
g[y].push_back(P(x,z));
}
for(int i=0;i<=m;i++)
for(int j=0;j<(1<<n);j++)d[i][j] = 10000.0;
d[a][0] = 0.0;
priority_queue<P2,vector<P2>,greater<P2> > q;
q.push(P2(0.0,P(a,0)));
double ans = 10000.0;
while(!q.empty()){
P2 p = q.top(); q.pop();
double dis = p.first;
int c = p.second.first, ti = p.second.second;
if(c==b){ans = dis; break;}
for(int i=0;i<(int)g[c].size();i++){
int nc = g[c][i].first;
for(int j=0;j<n;j++){
if( (ti>>j) & 1 )continue;
int nt = ti+(1<<j);
if(t[j]==0){
cout << "Impossible\n";
return;
}
double nd = dis + (double)g[c][i].second/t[j];
if(d[nc][nt] > nd){
d[nc][nt] = nd;
q.push(P2(nd,P(nc,nt)));
}
}
}
}
if(ans+EPS>10000.0)printf("Impossible\n");
else printf("%.5lf\n",ans);
}
} | a.cc: In function 'int main()':
a.cc:53:13: error: return-statement with no value, in function returning 'int' [-fpermissive]
53 | return;
| ^~~~~~
|
s148259919 | p00719 | C++ | #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#define INF (1<<29)
using namespace std;
int main(void){
int n,m,p,a,b,x,y,z,in;
double dp[(1<<8)][31],graph[31][31];
vector<int>t;
while(cin >> n >> m >> p >> a >> b){
if(!(n|m|p|a|b))break;
t.clear();
fill(graph[0],graph[31],-1);
fill(dp[0],dp[(1<<8)],INF);
for(int i=0;i<n;i++){
cin >> in;
t.push_back(in);
}
for(int i=0;i<p;i++){
cin >> x >> y >> z;
graph[x][y]=graph[y][x]=z;
}
dp[0][a]=0;
double res=INF;
for(int S=0;S<(1<<n);S++){
res=min(res,dp[S][b]);
for(int v=1;v<=m;v++){
for(int i=0;i<n;i++){
if(!(S>>i & 1)){
for(int u=1;u<=m;u++){
if(graph[v][u]<0)continue;
dp[S|(1<<i)][u]=min(dp[S|(1<<i)][u],dp[S][v]+graph[v][u]/t[i]);
}
}
}
}
} | a.cc: In function 'int main()':
a.cc:48:6: error: expected '}' at end of input
48 | }
| ^
a.cc:16:38: note: to match this '{'
16 | while(cin >> n >> m >> p >> a >> b){
| ^
a.cc:48:6: error: expected '}' at end of input
48 | }
| ^
a.cc:10:15: note: to match this '{'
10 | int main(void){
| ^
|
s736963701 | p00719 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, m, p, a, b;
while(true) {
cin >> n >> m >> p >> a >> b;
if( !m && !n && !p && !a && !b ) {
break;
}
vector< vector< double > > dp(1 << n, vector< double >(m + 1,INT_MAX / 4));
vector< int > t(n);
vector< vector< int > > map(m + 1, vector< int >(m + 1, INT_MAX / 4));
for(int i = 0; i < n; i++) {
cin >> t[i];
}
for(int i = 0; i < p; i++) {
int x, y, z;
cin >> x >> y >> z;
map[x][y] = z;
map[y][x] = z;
}
dp[0][a] = 0;
for(int s = 0; s < (1 << n); s++) {
for(int i = 0; i < n; i++) {
for(int j = 1; j <= m; j++) {
for(int k = 1; k <= m; k++) {
if(map[j][k] == INT_MAX / 4) {
continue;
}
if(!(s >> i & 1)) {
int next = s | (1 << i);
dp[next][k] = min(dp[next][k], dp[s][j] + ((double)map[j][k] / t[i]));
}
}
}
}
}
double ans = INT_MAX / 4;
for(int s = 0; s < (1 << n); s++) {
ans = min(ans, dp[s][b]);
}
if(ans == INT_MAX / 4) {
cout << "Inmpossible" << endl;
} else {
cout << ans << endl;
}
}
} | a.cc: In function 'int main()':
a.cc:18:78: error: 'INT_MAX' was not declared in this scope
18 | vector< vector< double > > dp(1 << n, vector< double >(m + 1,INT_MAX / 4));
| ^~~~~~~
a.cc:5:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
4 | #include <algorithm>
+++ |+#include <climits>
5 |
|
s957268311 | p00719 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;
vector< vector<int> > dist;//道のりvectorが入っているvector
int n,m,p,a,b;
int t[8];
int map[30][30];
void rec(vector<int> vec,int pos){
if(pos==b){
dist.push_back(vec);
}else if(vec.size()!=n){
for(int j=0;j<m;j++){
if(map[pos][j]!=0){
vec.push_back(map[pos][j]);
rec(vec,j);
vec.erase(vec.end()-1);
}
}
}
return;
}
int main(){
while(1){
cin >> n >> m >> p >> a >> b;
if(!n&&!m&&!p&&!a&&!b) break;
for(int i=0;i<n;i++){
scanf("%d",&t[i]);
}
a--;
b--;
memset(map,0,sizeof(map));
for(int i=0;i<p;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
map[x-1][y-1] = z;
map[y-1][x-1] = z;
}
vector<int> first;
rec(first,a);
sort(t,t+n);
if(dist.size()){
double min = 10000000;
for(int i=0;i<dist.size();i++){
double sum = 0;
sort(dist[i].begin(),dist[i].end());
for(int j=0;j<dist[i].size();j++){
//printf("t[%d]=%d\n",n-1-j,t[n-1-j]);
sum += (double)dist[i][dist[i].size()-1-j] / t[n-1-j];
}
if(sum<min){
min = sum;
}
}
printf("%lf\n",min);
}else{
cout << "Impossible" << endl;
}
dist.clear();
}
} | a.cc: In function 'int main()':
a.cc:38:5: error: 'memset' was not declared in this scope
38 | memset(map,0,sizeof(map));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <queue>
+++ |+#include <cstring>
5 | #define INF 10000000
a.cc:49:5: error: 'sort' was not declared in this scope; did you mean 'short'?
49 | sort(t,t+n);
| ^~~~
| short
|
s806455908 | p00720 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <tuple>
using namespace std;
typedef tuple<double, int, int> tdii;
struct Route {
vector<double> t, vx, vy, x, y;
explicit Route(int n = 0) : t(n), vx(n), vy(n), x(n), y(n) { }
};
vector<double> merge(const Route &a, const Route &b){
vector<double> result;
set_union(
a.t.begin(), a.t.end(), b.t.begin(), b.t.end(),
back_inserter(result));
return result;
}
Route interpolate(const Route &r, const vector<double> &t){
Route result(t.size());
for(int i = 0, j = 0; i < t.size(); ++i){
while(r.t[j] < t[i]){ ++j; }
result.t[i] = t[i];
if(r.t[j] == t[i]){
result.vx[i] = r.vx[j];
result.vy[i] = r.vy[j];
result.x[i] = r.x[j];
result.y[i] = r.y[j];
}else{
const double dt = r.t[j] - t[i];
const double vx = r.vx[j - 1], vy = r.vy[j - 1];
result.vx[i] = vx;
result.vy[i] = vy;
result.x[i] = r.x[j] - vx * dt;
result.y[i] = r.y[j] - vy * dt;
}
}
return result;
}
inline double pow2(double x){ return x * x; }
int main(){
ios_base::sync_with_stdio(false);
while(true){
int n, end_t, r;
cin >> n >> end_t >> r;
if(n == 0 && end_t == 0 && r == 0){ break; }
vector<string> names(n);
vector<Route> routes(n);
for(int i = 0; i < n; ++i){
Route &r = routes[i];
cin >> names[i];
while(true){
int t, vx, vy;
cin >> t >> vx >> vy;
r.t.push_back(t);
r.vx.push_back(vx);
r.vy.push_back(vy);
if(t == end_t){ break; }
}
const int m = r.t.size();
r.x.resize(m);
r.y.resize(m);
r.x[0] = r.vx[0];
r.y[0] = r.vy[0];
for(int j = 1; j < m; ++j){
const double dt = r.t[j] - r.t[j - 1];
r.x[j] = r.x[j - 1] + r.vx[j] * dt;
r.y[j] = r.y[j - 1] + r.vy[j] * dt;
r.vx[j - 1] = r.vx[j];
r.vy[j - 1] = r.vy[j];
}
}
vector<tdii> events;
for(int i = 0; i < n; ++i){
const Route &ri = routes[i];
for(int j = i + 1; j < n; ++j){
const Route &rj = routes[j];
const vector<double> t = merge(ri, rj);
const Route &pri = interpolate(ri, t);
const Route &prj = interpolate(rj, t);
const int m = t.size();
for(int k = 0; k + 1 < m; ++k){
const double dvx = pri.vx[k] - prj.vx[k];
const double dvy = pri.vy[k] - prj.vy[k];
const double dx = pri.x[k] - prj.x[k];
const double dy = pri.y[k] - prj.y[k];
const double a = pow2(dvx) + pow2(dvy);
const double b = 2 * (dvx * dx + dvy * dy);
const double c = pow2(dx) + pow2(dy) - pow2(r);
const double d = b * b - 4 * a * c;
double t0 = t[k], t1 = t[k];
if(a == 0 || d < 0){
if(a * t[k] * t[k] + b * t[k] + c <= r * r){
t1 = t[k + 1];
}
}else{
t0 = (-b - sqrt(d)) / (2 * a);
t1 = (-b + sqrt(d)) / (2 * a);
}
if(t0 > t1){ swap(t0, t1); }
t0 = max(t0, t[k]);
t1 = min(t1, t[k + 1]);
if(t0 >= t1){ continue; }
events.push_back(tdii(t0, i, j));
events.push_back(tdii(t1, i, j));
}
}
}
sort(events.begin(), events.end());
vector<int> done(n);
queue<int> q;
vector< vector<int> > mat(n, vector<int>(n));
done[0] = 1;
for(int i = 0; i < events.size(); ++i){
const int a = get<1>(events[i]);
const int b = get<2>(events[i]);
mat[a][b] ^= 1;
mat[b][a] ^= 1;
if(done[a] == done[b]){ continue; }
const int root = (done[a] ? b : a);
done[root] = 1;
q.push(root);
while(!q.empty()){
const int u = q.front();
q.pop();
for(int v = 0; v < n; ++v){
if(mat[u][v] == 0 || done[v]){ continue; }
done[v] = 1;
q.push(v);
}
}
}
vector<string> answer;
for(int i = 0; i < n; ++i){
if(done[i]){ answer.push_back(names[i]); }
}
sort(answer.begin(), answer.end());
for(int i = 0; i < answer.size(); ++i){
cout << answer[i] << endl;
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:102:60: error: 'sqrt' was not declared in this scope
102 | t0 = (-b - sqrt(d)) / (2 * a);
| ^~~~
|
s598543764 | p00720 | C++ | Unacceptable submission | a.cc:1:1: error: 'Unacceptable' does not name a type
1 | Unacceptable submission
| ^~~~~~~~~~~~
|
s223093713 | p00720 | C++ | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define EQ(a,b) (abs((a)-(b)) < EPS)
using namespace std;
typedef long double D;
typedef complex<D> P;
typedef pair<int,int> pii;
typedef pair<D, pii> data;
typedef vector<int> vi;
const D EPS = 1e-10;
const D PI = acos(-1);
const D INF = 1e15;
class UF{
vi parent,rank;
public:
UF(int n):parent(n,-1),rank(n,0){ }
int find(int x){ return (parent[x]<0)?x:(parent[x] = find(parent[x])); }
void unite(int x,int y){
x = find(x); y = find(y);
if(x==y)return;
if(rank[x] < rank[y])parent[x] = y;
else parent[y] = x;
if(rank[x] == rank[y])rank[x]++;
}
bool same(int x,int y){return find(x)==find(y);}
};
int n;
string name[110];
D T,r,x[110],y[110],t[110][1100];
D vx[110][1100], vy[110][1100];
vector<D> cal(int a, int b){
//cerr << a << " " << b << endl;
vector<D> res;
P pa = P(x[a],y[a]), pb = P(x[b],y[b]);
if( abs(pa-pb)<r+EPS )res.push_back(0);
int ta=1, tb=1;
D cur = 0, nxt = min(t[a][ta],t[b][tb]);
while(!EQ(cur,T)){
D tx = pa.real() - pb.real(), ty = pa.imag() - pb.imag();
D tvx = vx[a][ta] - vx[b][tb], tvy = vy[a][ta] - vy[b][tb];
//cerr << vx[a][ta] << " " << vy[a][ta] << " " << vx[b][tb] << " " << vy[b][tb] << endl;
D A = tvx*tvx + tvy*tvy, B = 2*tvx*tx + 2*tvy*ty, C = tx*tx + ty*ty - r*r;
D d = B*B - 4*A*C;
vector<D> sol;
//cerr << A << " " << B << " " << C << endl;
if(EQ(A,0)){
if(!EQ(B,0))sol.push_back(-C/B);
}else if(EQ(d,0)){
sol.push_back(-B/2/A);
}else if(d>EPS){
sol.push_back( (-B - sqrt(d))/2/A );
sol.push_back( (-B + sqrt(d))/2/A );
}
rep(i,sol.size()){
//cerr << sol[i] << endl;
if(sol[i]+EPS < 0 || nxt-cur+EPS < sol[i])continue;
res.push_back(cur + sol[i]);
}
cur = nxt;
if(EQ(t[a][ta],cur)){
D dif = t[a][ta] - t[a][ta-1];
pa += P(vx[a][ta]*dif, vy[a][ta]*dif);
ta++;
}
if(EQ(t[b][tb],cur)){
D dif = t[b][tb] - t[b][tb-1];
pb += P(vx[b][tb]*dif, vy[b][tb]*dif);
tb++;
}
nxt = min(t[a][ta],t[b][tb]);
}
return res;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
while(cin >> n >> T >> r){
if(n==0)break;
rep(i,n){
cin >> name[i];
cin >> t[i][0] >> x[i] >> y[i];
for(int j=0;;j++){
cin >> t[i][j+1] >> vx[i][j+1] >> vy[i][j+1];
if(EQ(t[i][j+1], T))break;
}
}
vector<data> event;
rep(i,n)rep(j,i){
vector<D> sub_event = cal(i,j);
for(D d : sub_event){
event.push_back(data(d, pii(i,j)));
}
}
sort(all(event));
/*
rep(i,event.size()){
cerr << event[i].first << " " << event[i].second.first << " " << event[i].second.second << endl;
}
*/
bool prop[110];
memset(prop,0,sizeof(prop));
prop[0] = true;
rep(i,event.size()){
if(event[i].first>T+EPS)break;
UF uf(n);
uf.unite(event[i].second.first,event[i].second.second);
while(i<(int)event.size() && EQ(event[i].first,event[i+1].first)){
i++;
uf.unite(event[i].second.first,event[i].second.second);
}
bool group[110];
memset(group,0,sizeof(group));
rep(j,n){
if(prop[j])group[uf.find(j)] = true;
}
//rep(j,n)cerr << group[j] << " "; cerr << endl;
rep(j,n){
if(group[uf.find(j)])prop[j] = true;
}
}
vector<string> ans;
rep(i,n){
if(prop[i])ans.push_back(name[i]);
}
sort(all(ans));
for(string s : ans)cout << s << endl;
}
} | a.cc: In function 'int main()':
a.cc:104:16: error: template argument 1 is invalid
104 | vector<data> event;
| ^
a.cc:104:16: error: template argument 2 is invalid
a.cc:108:15: error: request for member 'push_back' in 'event', which is of non-class type 'int'
108 | event.push_back(data(d, pii(i,j)));
| ^~~~~~~~~
a.cc:108:25: error: reference to 'data' is ambiguous
108 | event.push_back(data(d, pii(i,j)));
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:9:22: note: 'typedef struct std::pair<long double, std::pair<int, int> > data'
9 | typedef pair<D, pii> data;
| ^~~~
a.cc:3:20: error: request for member 'begin' in 'event', which is of non-class type 'int'
3 | #define all(a) (a).begin(),(a).end()
| ^~~~~
a.cc:111:10: note: in expansion of macro 'all'
111 | sort(all(event));
| ^~~
a.cc:3:32: error: request for member 'end' in 'event', which is of non-class type 'int'
3 | #define all(a) (a).begin(),(a).end()
| ^~~
a.cc:111:10: note: in expansion of macro 'all'
111 | sort(all(event));
| ^~~
a.cc:122:17: error: request for member 'size' in 'event', which is of non-class type 'int'
122 | rep(i,event.size()){
| ^~~~
a.cc:2:38: note: in definition of macro 'rep'
2 | #define rep(i,n) for(int i=0;i<(int)(n);i++)
| ^
a.cc:123:15: error: invalid types 'int[int]' for array subscript
123 | if(event[i].first>T+EPS)break;
| ^
a.cc:126:21: error: invalid types 'int[int]' for array subscript
126 | uf.unite(event[i].second.first,event[i].second.second);
| ^
a.cc:126:43: error: invalid types 'int[int]' for array subscript
126 | uf.unite(event[i].second.first,event[i].second.second);
| ^
a.cc:127:26: error: request for member 'size' in 'event', which is of non-class type 'int'
127 | while(i<(int)event.size() && EQ(event[i].first,event[i+1].first)){
| ^~~~
a.cc:127:44: error: invalid types 'int[int]' for array subscript
127 | while(i<(int)event.size() && EQ(event[i].first,event[i+1].first)){
| ^
a.cc:4:23: note: in definition of macro 'EQ'
4 | #define EQ(a,b) (abs((a)-(b)) < EPS)
| ^
a.cc:127:59: error: invalid types 'int[int]' for array subscript
127 | while(i<(int)event.size() && EQ(event[i].first,event[i+1].first)){
| ^
a.cc:4:27: note: in definition of macro 'EQ'
4 | #define EQ(a,b) (abs((a)-(b)) < EPS)
| ^
a.cc:129:23: error: invalid types 'int[int]' for array subscript
129 | uf.unite(event[i].second.first,event[i].second.second);
| ^
a.cc:129:45: error: invalid types 'int[int]' for array subscript
129 | uf.unite(event[i].second.first,event[i].second.second);
| ^
|
s485234791 | p00721 | C++ | #include<iostream>
#include<algorithm>
#include<queue>
#include<mpi.h>
#include<cstring>
using namespace std;
#define INF (1 << 29)
typedef pair< int , int > Pi;
int h, w;
char mas[50][50];
int graph[11][11];
int min_cost[50][50];
Pi gomi[11], st, gl;
int gomi_size, uoo;
int memo[12][1 << 11];
const int dy[] = { 1, 0, 0, -1}, dx[] = { 0, 1, -1, 0};
int rec(int idx, int used)
{
if(used == (1 << gomi_size) - 1) return 0;
if(memo[idx][used]) return memo[idx][used];
int ret = INF;
for(int i = 0; i < gomi_size; i++){
if(!(used & (1 << i)) && graph[idx][i] != -1){
ret = min(ret, rec(i, used | (1 << i)) + graph[idx][i]);
}
}
return memo[idx][used] = ret;
}
int bfs(Pi a, Pi b)
{
memset( min_cost, -1, sizeof(min_cost));
queue< Pi > que;
que.push(a);
min_cost[a.first][a.second] = 0;
while(!que.empty()){
Pi p = que.front(); que.pop();
if(p == b) return min_cost[p.first][p.second];
for(int i = 0; i < 4; i++){
int ny = p.first + dy[i], nx = p.second + dx[i];
if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
if(mas[ny][nx] != 'x' && min_cost[ny][nx] == -1){
min_cost[ny][nx] = min_cost[p.first][p.second] + 1;
que.push( Pi( ny, nx));
}
}
}
return -1;
}
int main(int argc, char* argv[])
{
MPI_Request req1, req2;
MPI_Status stat;
int tag = 0, rank, numprocs;
int rank_buff[11][11];
vector< Pi > my_bfs;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
while(true){
if(rank == 0){
cin >> w >> h;
}
MPI_Bcast( &w, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast( &h, 1, MPI_INT, 0, MPI_COMM_WORLD);
if(w == 0) break;
gomi_size = 0;
my_bfs.clear();
memset( memo, 0, sizeof(memo));
if(rank == 0){
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
cin >> mas[i][j];
if(mas[i][j] == '*' || mas[i][j] == 'o'){
gomi[gomi_size++] = Pi( i, j);
if(mas[i][j] == 'o') uoo = gomi_size - 1;
}
}
}
}
for(int i = 0; i < h; i++){
MPI_Bcast( mas[i], w, MPI_INT, 0, MPI_COMM_WORLD);
}
MPI_Bcast( &gomi_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
for(int i = 0, foo = 0; i < gomi_size; i++){ //送るプロセスの計算(めんどい
for(int j = i + 1; j < gomi_size; j++, foo = (foo + 1) % numprocs){
rank_buff[i][j] = foo;
if(foo == rank) my_bfs.push_back( Pi(i, j));
}
}
if(rank == 0){
for(int i = 0; i < gomi_size; i++){
for(int j = i + 1; j < gomi_size; j++){
if(rank_buff[i][j] != 0){
MPI_Isend( &gomi[i], 1, MPI::TWOINT, rank_buff[i][j], tag, MPI_COMM_WORLD, &req1);
MPI_Isend( &gomi[j], 1, MPI::TWOINT, rank_buff[i][j], tag, MPI_COMM_WORLD, &req2);
}
}
}
for(int i = 0; i < my_bfs.size(); i++){
Pi p = my_bfs[i];
graph[p.first][p.second] = bfs( gomi[p.first], gomi[p.second]);
}
for(int i = 0; i < gomi_size; i++){
for(int j = i + 1; j < gomi_size; j++){
if(rank_buff[i][j] != 0){
MPI_Irecv( &graph[i][j], 1, MPI_INT, rank_buff[i][j], tag, MPI_COMM_WORLD, &req1);
MPI_Wait( &req1, &stat);
graph[j][i] = graph[i][j];
}
}
}
} else {
for(int i = 0; i < my_bfs.size(); i++){
MPI_Irecv( &st, 1, MPI::TWOINT, 0, tag, MPI_COMM_WORLD, &req1);
MPI_Irecv( &gl, 1, MPI::TWOINT, 0, tag, MPI_COMM_WORLD, &req2);
MPI_Wait(&req1, &stat);
MPI_Wait(&req2, &stat);
int res = bfs( st, gl);
MPI_Isend( &res, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &req1);
}
}
//巡回セールスマン!!
//さのぴーさんよろしく
if(rank == 0){
int ret = rec( uoo, 1 << uoo);
if(ret != INF) cout << ret << endl;
else cout << -1 << endl;
}
}
MPI_Finalize();
return(0);
} | a.cc:4:9: fatal error: mpi.h: No such file or directory
4 | #include<mpi.h>
| ^~~~~~~
compilation terminated.
|
s175145886 | p00721 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
const int inf = 1 << 28;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int w, h;
inline bool inrect(int x, int y){
return 0 <= x && x < h && 0 <= y && y < w;
}
int solve(vector<string>& c){
vector<int> xs, ys;
rep(i, h)rep(j, w){
if(c[i][j] == 'o')xs.insert(xs.begin(), i), ys.insert(ys.begin(), j);
if(c[i][j] == '*')xs.push_back(i), ys.push_back(j);
}
int n = (int)xs.size();
vector<vector<int> > costs(n, vector<int>(n, inf));
rep(i, n){
vector<vector<int> > mem(h, vector<int>(w, inf)); mem[xs[i]][ys[i]] = 0;
typedef tuple<int, int, int> State;
priority_queue<State> q;
for(q.emplace(0, xs[i], ys[i]); !q.empty();){
int cost, x, y;
tie(cost, x, y) = q.top(); q.pop();
if(mem[x][y] != -cost)continue;
rep(k, 4){
int nx = x + dx[k], ny = y + dy[k];
if(!inrect(nx, ny) || c[nx][ny] == 'x' || mem[nx][ny] <= 1 - cost)continue;
mem[nx][ny] = 1 - cost;
q.emplace(-mem[nx][ny], nx, ny);
}
}
rep(j, n)costs[i][j] = mem[xs[j]][ys[j]];
}
if(find(all(costs[0]), inf) != costs[0].end())return -1;
vector<int> mem(1 << n, inf); mem[1 << 0] = 0;
typedef tuple<int, int, int> State;
priority_queue<State> q;
for(q.emplace(0, 1 << 0, 0); !q.empty();){
int cost, vis, v;
tie(cost, vis, v) = q.top(); q.pop();
if(mem[vis] != -cost)continue;
if(vis == (1 << n) - 1)return -cost;
rep(i, n){
if(vis >> i & 1 || mem[vis | 1 << i] <= costs[v][i] - cost)continue;
mem[vis | 1 << i] = costs[v][i] - cost;
q.emplace(-mem[vis | 1 << i], vis | 1<< i, i);
}
}
return -1;
}
int main(){
while(cin >> w >> h, w|h){
vector<string> c(h);
rep(i, h)cin >> c[i];
cout << solve(c) << '\n';
}
return 0;
} | a.cc: In function 'int solve(std::vector<std::__cxx11::basic_string<char> >&)':
a.cc:45:12: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, const int&)'
45 | if(find(all(costs[0]), inf) != costs[0].end())return -1;
| ~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
from /usr/include/c++/14/bits/basic_ios.h:37,
from /usr/include/c++/14/ios:46,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
435 | find(istreambuf_iterator<_CharT> __first,
| ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: template argument deduction/substitution failed:
a.cc:45:12: note: '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
45 | if(find(all(costs[0]), inf) != costs[0].end())return -1;
| ~~~~^~~~~~~~~~~~~~~~~~~~
|
s362799577 | p00721 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
int const inf = 1 << 29;
int main(){
int w, h;
while (cin >> w >> h && w | h){
vector<string> grid(h);
vector<pair<int,int>> node;
rep(i, h){
cin >> grid[i];
rep(j, grid[i].size())if (grid[i][j] == 'o')node.emplace_back(i, j);
}
rep(i, h)rep(j, w){
if (grid[i][j] == '*')node.emplace_back(i, j);
}
static int d[20][20];
rep(i, 20)rep(j, 20)d[i][j] = inf;
rep(i, node.size()){
int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };
queue<pair<int, int>> q;
static int dist[25][25];
rep(j, h)rep(k, w)dist[j][k] = inf;
dist[node[i].first][node[i].second] = 0;
q.emplace(node[i]);
while (q.size()){
auto p = q.front(); q.pop();
int cx = p.second, cy = p.first;
rep(j, 4){
int nx = cx + dx[j], ny = cy + dy[j];
if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
if (grid[ny][nx] == 'x') continue;
if (dist[ny][nx] > dist[cy][cx] + 1){
dist[ny][nx] = dist[cy][cx] + 1;
q.emplace(ny, nx);
}
}
}
rep(j, node.size()){
d[i][j] = dist[node[j].first][node[j].second];
}
}
int idx[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
long long ans = inf;
do{
long long t = 0;
rep(i, node.size() - 1){
t += d[idx[i]][idx[i + 1]];
}
ans = min(t, ans);
} while (next_permutation(idx + 1, idx + node.size()));
if (ans >= inf)ans = -1;
cout << ans << endl;
}
} | a.cc: In function 'int main()':
a.cc:65:18: error: 'next_permutation' was not declared in this scope
65 | } while (next_permutation(idx + 1, idx + node.size()));
| ^~~~~~~~~~~~~~~~
|
s278275293 | p00721 | C++ | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define INF (int)(999999999/2)
#define eps 1e-9
#define MAX_N 5000
int w,h;
int fie[30][30];
string data[30];
void bfs(int yy,int xx){
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
queue<pii> que;
que.push(pii(yy,xx));
bool used[30][30]={};
while(que.size()){
int y=que.front().first,x=que.front().second;
que.pop();
used[y][x]=true;
rep(i,4){
int ddy=y+dy[i],ddx=x+dx[i];
if(ddy<0||ddx<0||ddy>=h||ddx>=w||data[ddy][ddx]=='x'||used[ddy][ddx])continue;
fie[ddy][ddx]=fie[y][x]+1;
que.push(pii(ddy,ddx));
}
}
}
int main(){
while(cin>>w>>h&&w&&h){
int v=0;
rep(i,h){
cin>>data[i];
}
vector<pii> p;
rep(i,h)rep(j,w)if(data[i][j]=='o'){p.pb(pii(i,j));v++;}
rep(i,h)rep(j,w)if(data[i][j]=='*'){p.pb(pii(i,j));v++;}
map< pair<pii,pii> , int > pass;
rep(i,p.size()){
rep(i,30)rep(j,30)fie[i][j]=INF;
fie[p[i].first][p[i].second]=0;
bfs(p[i].first,p[i].second);
rep(j,p.size()){
pass[make_pair(p[i],p[j])]=fie[p[j].first][p[j].second];
}
}
vector<int> num;
rep(i,v)num.pb(i);
sort(all(num));
int mini=INF;
do{
if(num[0]!=0)continue;
int sum=0;
rep(i,v-1){
sum+=pass[ make_pair(p[num[i]],p[num[i+1]]) ];
}
mini=min(mini,sum);
}while(next_permutation(all(num)));
if(mini==INF)cout<<"-1"<<endl;
else cout<<mini<<endl;
}
} | a.cc: In function 'void bfs(int, int)':
a.cc:29:46: error: reference to 'data' is ambiguous
29 | if(ddy<0||ddx<0||ddy>=h||ddx>=w||data[ddy][ddx]=='x'||used[ddy][ddx])continue;
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bitset:52,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:13:8: note: 'std::string data [30]'
13 | string data[30];
| ^~~~
a.cc: In function 'int main()':
a.cc:40:18: error: reference to 'data' is ambiguous
40 | cin>>data[i];
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:13:8: note: 'std::string data [30]'
13 | string data[30];
| ^~~~
a.cc:44:28: error: reference to 'data' is ambiguous
44 | rep(i,h)rep(j,w)if(data[i][j]=='o'){p.pb(pii(i,j));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:13:8: note: 'std::string data [30]'
13 | string data[30];
| ^~~~
a.cc:45:28: error: reference to 'data' is ambiguous
45 | rep(i,h)rep(j,w)if(data[i][j]=='*'){p.pb(pii(i,j));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:13:8: note: 'std::string data [30]'
13 | string data[30];
| ^~~~
|
s149544521 | p00721 | C++ | #include <iostream>
#include <tuple>
#include <vector>
#include <queue>
char stage[20][20];
int cost[1024][10];
int dis[10][10];
int w, h;
typedef std::tuple<int, int, int> T;
std::vector<T> pos_to_num;
long long unsigned PopCount(long long unsigned x) {
x = (x & 0x5555555555555555ULL) + ((x & 0xAAAAAAAAAAAAAAAAULL) >> 1);
x = (x & 0x3333333333333333ULL) + ((x & 0xCCCCCCCCCCCCCCCCULL) >> 2);
x = (x & 0x0F0F0F0F0F0F0F0FULL) + ((x & 0xF0F0F0F0F0F0F0F0ULL) >> 4);
x *= 0x0101010101010101ULL;
return x;
}
void dijkstra(int sx, int sy)
{
int c[20][20] = {0};
int f[20][20] = {0};
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
std::queue<std::tuple<int,int>> q;
q.push(std::make_tuple(sx, sy));
f[sx][sy] = 1;
while(!q.empty()) {
auto a = q.front(); q.pop();
int x = std::get<0>(a);
int y = std::get<1>(a);
for ( int i = 0; i < 4; ++i ) {
int nx = x + dx[i];
int ny = y + dy[i];
if ( nx < 0 || nx >= w ) continue;
if ( ny < 0 || ny >= h ) continue;
if ( stage[nx][ny] == 'x' ) continue;
if ( f[nx][ny] == 1 ) continue;
c[nx][ny] = c[x][y] + 1;
f[nx][ny] = 1;
q.push(std::make_tuple(nx, ny));
}
}
if ( stage[sx][sy] == 'o' ) {
for ( int i = 0; i < pos_to_num.size(); ++i ) {
cost[0][std::get<2>(pos_to_num[i])] = c[std::get<0>(pos_to_num[i])][std::get<1>(pos_to_num[i])];
}
} else if ( stage[sx][sy] == '*' ) {
int num;
for ( int i = 0; i < pos_to_num.size(); ++i ) {
if ( sx == std::get<0>(pos_to_num[i]) && sy == std::get<1>(pos_to_num[i]) ) {
num = std::get<2>(pos_to_num[i]);
}
}
for ( int i = 0; i < pos_to_num.size(); ++i ) {
dis[num][std::get<2>(pos_to_num[i])] = c[std::get<0>(pos_to_num[i])][std::get<1>(pos_to_num[i])];
}
}
}
int main()
{
while ( true ) {
for ( int i = 0; i < 1024; ++i ) {
for ( int j = 0; j < 10; ++j ) {
cost[i][j] = 0xfffff;
}
}
std::cin >> w >> h;
if ( w == 0 && h == 0 ) return 0;
int sx, sy;
int k = 0;
for ( int i = 0; i < h; ++i ) {
for ( int j = 0; j < w; ++j ) {
std::cin >> stage[j][i];
if ( stage[j][i] == '*' ) {
pos_to_num.push_back(T(j, i, k));
k++;
}
if ( stage[j][i] == 'o' ) {
sx = j; sy = i;
}
}
}
dijkstra(sx, sy);
for ( auto &v: pos_to_num ) {
dijkstra(std::get<0>(v), std::get<1>(v));
}
std::vector<std::tuple<int, int>> table(1<<k);
for ( int i = 0; i < (1<<k); ++i ) {
table[i] = std::make_tuple(PopCount(i), i);
}
std::sort(table.begin(), table.end());
for ( int i = 1; i < (1<<k); ++i ) {
int q = std::get<1>(table[i]);
for ( int j = 0; j < k; ++j ) {
if ( q & (1<<j) ) {
for ( int l = 0; l < k; ++l ) {
int c = cost[q^(1<<j)][j] + dis[j][l];
cost[q][l] = (c < cost[q][l]) ? c : cost[q][l];
//std::cout << "state:" << q << " to:" << l << " cost:" << cost[q][l] << std::endl;
}
}
}
}
int min = 0xfffff;
for ( int i = 0; i < k; ++i ) {
if ( min > cost[(1<<k)-1][i] ) min = cost[(1<<k)-1][i];
}
if ( min == 0xfffff || min == 0 ) {
std::cout << -1 << std::endl;
} else {
std::cout << min << std::endl;
}
}
return 0;
} | a.cc: In function 'int main()':
a.cc:105:22: error: 'sort' is not a member of 'std'; did you mean 'qsort'?
105 | std::sort(table.begin(), table.end());
| ^~~~
| qsort
|
s106263521 | p00721 | C++ | #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <chrono>
#include <queue>
#include <functional>
using namespace std;
#define INF 1e9
//????????????
class Timer {
chrono::high_resolution_clock::time_point start, end;
double limit;
public:
Timer() {
start = chrono::high_resolution_clock::now();
}
Timer(double l) {
start = chrono::high_resolution_clock::now();
limit = l;
}
double getTime() {
end = chrono::high_resolution_clock::now();
return chrono::duration<double>(end - start).count();
}
bool Over() {
if (getTime() > limit) {
return true;
}
return false;
}
void setLimit(double l) {
limit = l;
}
void setStart() { start = chrono::high_resolution_clock::now(); }
};
struct POINT {
int x, y;
POINT() {}
POINT(int x_, int y_) { x = x_, y = y_; }
bool operator<(const POINT& r)const {
return x + y < r.x + r.y;
}
POINT operator+(const POINT& r)const {
return POINT(x + r.x, y + r.y);
}
};
struct STATUS {
int dist;
int id;
vector<bool>used;
STATUS() {}
STATUS(int dist_, int id_, vector<bool>&used_) {
dist = dist_;
id = id_;
used = used_;
}
bool operator>(const STATUS& r)const {
return dist > r.dist;
}
};
int W, H;
vector<vector<int>>MAP;
int status[20][20];
int cost[20][20];
void dijkstra(POINT p) {
int v[] = { -1,0,1,0 };
int h[] = { 0,1,0,-1 };
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
status[i][j] = 0;
cost[i][j] = INF;
}
}
cost[p.x][p.y] = 0;
status[p.x][p.y] = 1;
priority_queue<pair<int, POINT>, vector<pair<int, POINT>>, greater<pair<int, POINT>>>U;
U.push(make_pair(cost[p.x][p.y], p));
while (!U.empty()) {
//??¢?´¢???????????£??????????????§?????????????°???????
POINT u = U.top().second; U.pop();
if (status[u.x][u.y] == -1) continue;
status[u.x][u.y] = -1;
//?????????????°????????????¢???
for (int i = 0; i < 4; i++) {
POINT np = u + POINT(v[i], h[i]);
if (np.x < 0 || np.x >= H || np.y < 0 || np.y >= W)continue;
if (MAP[np.x][np.y] == 1)continue;
if (status[np.x][np.y] != -1) {
if (cost[np.x][np.y] > cost[u.x][u.y] + 1) {
cost[np.x][np.y] = cost[u.x][u.y] + 1;
status[np.x][np.y] = 1;
U.push(make_pair(cost[np.x][np.y], np));
}
}
}
}
}
int main()
{
while (1) {
cin >> W >> H;
if (W == 0 && H == 0)break;
MAP.assign(H,vector<int>(W,0));
vector<POINT>pos;
int cnt = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char c; cin >> c;
if (c == '*') {
POINT p = POINT(i, j);
pos.push_back(p);
cnt++;
}
else if (c == 'x')MAP[i][j] = 1;
else if (c == 'o') {
POINT sp = POINT(i, j);
pos.insert(pos.begin(), sp);
cnt++;
}
}
}
bool fin = false;
vector<vector<int>>dist(cnt);
for (int i = 0; i < cnt; i++) {
dist[i].resize(cnt);
dijkstra(pos[i]);
for (int j = 1; j < cnt; j++) {
int distance = cost[pos[j].x][pos[j].y];
if (distance == INF)fin = true;
dist[i][j] = distance;
}
}
if (fin) {
cout << -1 << endl;
continue;
}
Timer tmr(0.5);
vector<priority_queue<STATUS, vector<STATUS>, greater<STATUS>>>STAT(cnt);
STAT[0].push(STATUS(0,0,vector<bool>(cnt)));
while (1) {
if (tmr.Over())break;
for (int i = 0; i < cnt - 1; i++) {
if (STAT[i].empty())continue;
STATUS st = STAT[i].top(); STAT[i].pop();
for (int j = 1; j < cnt; j++) {
if (st.used[j])continue;
st.used[j] = true;
STAT[i + 1].push(STATUS(st.dist + dist[st.id][j], j, st.used));
st.used[j] = false;
}
}
}
STATUS last = STAT[cnt - 1].top();
cout << last.dist << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:168:41: error: cannot bind non-const lvalue reference of type 'std::vector<bool>&' to an rvalue of type 'std::vector<bool>'
168 | STAT[0].push(STATUS(0,0,vector<bool>(cnt)));
| ^~~~~~~~~~~~~~~~~
a.cc:66:49: note: initializing argument 3 of 'STATUS::STATUS(int, int, std::vector<bool>&)'
66 | STATUS(int dist_, int id_, vector<bool>&used_) {
| ~~~~~~~~~~~~~^~~~~
|
s436810866 | p00721 | C++ | #include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
const int INF = 100000000;
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
bool in_range(int a, int b){ return a >= 0 && a < b;}
void bfs(map<int,int> &M, vector<int> &G, vector<string> C, int s){
int h = C.size(), w = C[0].length();
queue< pair<int,int> > que;
que.emplace(s,0);
while(!que.empty()){
int p = que.front().first, d = que.front().second;
que.pop();
if(M[p])
G[M[p]-1] = min(d,G[M[p]-1]);
C[p/w][p%w] = 'x';
for(int i = 0; i < 4; ++i){
int x = p/w + dx[i], y = p%w + dy[i], p_ = x*w + y;
if(in_range(x,h) && in_range(y,w) && C[x][y] != 'x')
que.emplace(p_,d+1);
}
}
}
vector< vector<int> > make_graph(vector<string> &C, vector<int> &D){
int h = C.size(), w = C[0].length(), n = D.size();
map<int,int> M;
for(int i = 0; i < n; ++i){
M[D[i]] = i+1;
}
vector< vector<int> > G(n, vector<int>(n,INF));
for(int i = 0; i < n; ++i){
bfs(M,G[i],C,D[i]);
}
return G;
}
int main(){
int w, h;
while(cin >> w >> h, w){
vector<string> C(h);
vector<int> D;
int s;
for(int i = 0; i < h; ++i){
cin >> C[i];
for(int j = 0; j < w; ++j){
if(C[i][j] == 'o') s = i*w+j;
if(C[i][j] == '*'){
D.push_back(i*w+j);
}
}
}
D.push_back(s);
vector< vector<int> > G = make_graph(C,D);
int n = G.size()-1;
vector<int> V(n);
for(int i = 0; i < n; ++i) V[i] = i;
int ans = INF;
do{
int t = 0, v = n;
for(int i = 0; i < n; ++i){
t += G[v][V[i]];
v = V[i];
}
ans = min(ans,t);
}while(next_permutation(V.begin(),V.end()));
if(ans >= INF) ans = -1;
cout << ans << endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:70:12: error: 'next_permutation' was not declared in this scope
70 | }while(next_permutation(V.begin(),V.end()));
| ^~~~~~~~~~~~~~~~
|
s883315847 | p00721 | C++ | #include<iostream>
#include<string>
#include<queue>
using namespace std;
using P = pair<int, int>;
int w, h, m;
string map[20];
int d[20][20][20][20];
P dirty[20];
int diri[] = {-1, 0, 1, 0};
int dirj[] = {0, -1, 0, 1};
void bfs(int si, int sj) {
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
d[si][sj][i][j] = -1;
}
}
d[si][sj][si][sj] = 0;
queue<P> q;
q.push(make_pair(si, sj));
while (!q.empty()) {
P p = q.front();
q.pop();
int i = p.first;
int j = p.second;
int cost = d[si][sj][i][j];
for (int k = 0; k < 4; ++k) {
int ni = i + diri[k];
int nj = j + dirj[k];
if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
if (map[ni][nj] == 'x') continue;
//cout << ni << nj << " "<<d[si][sj][ni][nj]<< endl;
if (d[si][sj][ni][nj] != -1) continue;
d[si][sj][ni][nj] = cost + 1;
q.push(make_pair(ni, nj));
}
}
// for (int i = 0; i < h; ++i) {
// for (int j = 0; j < w; ++j) {
// cout << d[si][sj][i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
}
void solve() {
for (int i = 0; i < h; ++i) {
cin >> map[i];
}
m = 0;
int ri, rj;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (map[i][j] == '*') {
dirty[m] = make_pair(i, j);
m++;
bfs(i, j);
} else if (map[i][j] == 'o') {
ri = i;
rj = j;
bfs(i, j);
}
}
}
sort(dirty, dirty + m);
int mincost = 4000;
do {
int cost = 0;
int i = ri;
int j = rj;
for (int k = 0; k < m; ++k) {
int toi = dirty[k].first;
int toj = dirty[k].second;
cost += d[i][j][toi][toj];
if (d[i][j][toi][toj] == -1) {
mincost = -1;
break;
}
i = toi;
j = toj;
}
mincost = min(cost, mincost);
} while (next_permutation(dirty, dirty + m));
cout << mincost << endl;
}
int main() {
while (1) {
cin >> w >> h;
if (w == 0) break;
solve();
}
}
| a.cc: In function 'void solve()':
a.cc:73:5: error: 'sort' was not declared in this scope; did you mean 'short'?
73 | sort(dirty, dirty + m);
| ^~~~
| short
a.cc:92:14: error: 'next_permutation' was not declared in this scope
92 | } while (next_permutation(dirty, dirty + m));
| ^~~~~~~~~~~~~~~~
|
s040120275 | p00721 | C++ | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
struct Point {
int y;
int x;
int cost;
Point() {;}
Point(int y1, int x1, int c) : y(y1), x(x1), cost(c) {;}
};
int width;
int height;
char str[100];
char tile[30][30];
int dist[11][10];
int dirty_y[10];
int dirty_x[10];
int map[30][30];
bool check[30][30];
int dirty_tile;
int memo[1024][10];
int calc(int depth, int visit, int where) {
if (memo[visit][where] != -1) { return memo[visit][where]; }
if (depth == dirty_tile) { return 0; }
int ret = 0x0f0f0f0f;
for (int i = 0; i < dirty_tile; i++) {
if (visit & (1 << i)) { continue; }
int next_visit = visit | (1 << i);
ret = min(ret, calc(depth + 1, next_visit, i) + dist[where][i]);
}
return memo[visit][where] = ret;
}
int main() {
while (scanf("%d %d", &width, &height), width != 0 && height != 0) {
fgets(str, 99, stdin);
for (int i = 0; i < height; i++) {
fgets(tile[i], 29, stdin);
}
int start_y;
int start_x;
dirty_tile = 0;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (tile[y][x] == '*') {
dirty_y[dirty_tile] = y;
dirty_x[dirty_tile] = x;
map[y][x] = dirty_tile;
dirty_tile++;
} else if (tile[y][x] == 'o') {
start_y = y;
start_x = x;
}
}
}
dirty_y[dirty_tile] = start_y;
dirty_x[dirty_tile] = start_x;
map[start_y][start_x] = dirty_tile;
memset(dist, -1, sizeof(dist));
static const int dy[4] = { 1, -1, 0, 0 };
static const int dx[4] = { 0, 0, 1, -1 };
for (int i = 0; i < dirty_tile + 1; i++) {
queue<Point> que;
que.push(Point(dirty_y[i], dirty_x[i], 0));
memset(check, false, sizeof(check));
while (!que.empty()) {
Point now = que.front();
que.pop();
if (check[now.y][now.x]) { continue; }
check[now.y][now.x] = true;
if (tile[now.y][now.x] == '*') {
dist[i][map[now.y][now.x]] = now.cost;
}
for (int i = 0; i < 4; i++) {
int ny = now.y + dy[i];
int nx = now.x + dx[i];
if (ny < 0 || ny >= height || nx < 0 || nx >= width || check[ny][nx] || tile[ny][nx] == 'x') { continue; }
que.push(Point(ny, nx, now.cost + 1));
}
}
}
for (int i = 0; i < dirty_tile; i++) {
if (dist[dirty_tile][i] == -1) {
puts("-1");
goto next_loop;
}
}
memset(memo, -1, sizeof(memo));
printf("%d\n", calc(0, 0, dirty_tile));
next_loop:
;
}
} | a.cc: In function 'int main()':
a.cc:66:5: error: 'memset' was not declared in this scope
66 | memset(dist, -1, sizeof(dist));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <queue>
+++ |+#include <cstring>
5 |
|
s521380442 | p00721 | C++ | #include <iostream>
#include <string>
#include <queue>
using namespace std;
const int INF = 9999999;
int w, h;
string b[20];
int d[20][20];
char dx[] = {-1,1,0,0};
char dy[] = {0,0,-1,1};
void dist(int sx, int sy){
for(int i=0;i<20;i++)
for(int j=0;j<20;j++)
d[i][j] = INF;
queue< pair<int,int> > qu;
qu.push(make_pair(sx,sy));
d[sy][sx] = 0;
while(!qu.empty()){
pair<int, int> p = qu.front(); qu.pop();
int x = p.first, y = p.second;
for(int i=0;i<4;i++){
int nx = x + dx[i], ny = y + dy[i];
if(nx<0||nx>=w||ny<0||ny>=h||b[ny][nx]=='x') continue;
if(d[ny][nx] != INF) continue;
d[ny][nx] = d[y][x] + 1;
qu.push(make_pair(nx,ny));
}
}
}
int main(){
int c[11][11];
int x[11], y[11];
int ans[1<<11][11];
while(cin >> w >> h){
if(!(w||h)) break;
int num = 1;
for(int i=0;i<h;i++){
cin >> b[i];
for(int j=0;j<w;j++){
if(b[i][j]=='o') x[0] = j, y[0] = i;
if(b[i][j]=='*') x[num] = j, y[num++] = i;
}
}
bool flag = false;
memset(c,0,sizeof(c));
dist(x[0],y[0]);
for(int i=1;i<num;i++){
c[0][i] = d[y[i]][x[i]];
if(c[0][i] == INF) flag = true;
}
if(flag) { cout << -1 << endl; continue; }
for(int i=1;i<num;i++){
dist(x[i],y[i]);
for(int j=0;j<num;j++){
if(i==j) continue;
c[i][j] = d[y[j]][x[j]];
}
}
for(int i=0;i<(1<<num);i++) for(int j=0;j<num;j++) ans[i][j] = INF;
ans[1][0] = 0;
for(int i=0;i<(1<<num);i++){
for(int j=0;j<num;j++)
if((i>>j)&1)
for(int k=0;k<num;k++)
ans[i|(1<<k)][k] = min(ans[i|(1<<k)][k],ans[i][j]+c[j][k]);
}
int cost = INF;
for(int i=1;i<num;i++) cost = min(cost, ans[(1<<num)-1][i]);
cout << cost << endl;
}
} | a.cc: In function 'int main()':
a.cc:51:17: error: 'memset' was not declared in this scope
51 | memset(c,0,sizeof(c));
| ^~~~~~
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 |
|
s197016120 | p00721 | C++ | #include<iostream>
#include<cstdio>
#include<algorithm>
#include<deque>
#include<queue>
using namespace std;
int main(){
int h,w;
while(scanf("%d%d\n",&w,&h),w+h){
char board[22][22]={{0}};
deque<pair<int,int> > pos;
int count=3;
for(int i=1;i<=h;i++){
gets(&board[i][1]);
for(int j=1;j<=w;j++){
if(board[i][j]=='x') board[i][j]=0;
else if(board[i][j]=='.') board[i][j]=1;
else if(board[i][j]=='*'){
board[i][j]=count++;
pos.push_back(make_pair(j,i));
}else if(board[i][j]=='o'){
board[i][j]=2;
pos.push_front(make_pair(j,i));
}
}
}
/*
for(int i=0;i<h+2;i++){
for(int j=0;j<w+2;j++){
printf("%d ",board[i][j]);
}
puts("");
}
*/
//int darty=pos.size()-1;
int dist[11][11]={{0}};
bool possible=true;
for(int i=0;i<pos.size()-1;i++){
//dijkstra
int flag[22][22]={{0}};
int d[22][22];
for(int x=0;x<22;x++)
for(int y=0;y<22;y++)
d[y][x]=1000;
count=0;
priority_queue<pair<int,pair<int,int> > > q;
q.push(make_pair(0,make_pair(pos[i].first,pos[i].second)));
while(!q.empty()){
if(count==pos.size()) break;
int x=q.top().second.first,y=q.top().second.second,hy=q.top().first;
q.pop();
//printf("(%d,%d)=%d\n",x,y,-hy);
if(flag[y][x]!=0) continue;
flag[y][x]=1;
if(board[y][x]>=2){//darty or initial
//printf("test %d\n",board[y][x]-2);
dist[i][board[y][x]-2]=-hy;
dist[board[y][x]-2][i]=-hy;
count++;
}
if(board[y][x-1]!=0 && d[y][x-1]>-hy+1){
d[y][x-1]=-hy+1;
q.push(make_pair(hy-1,make_pair(x-1,y)));
}
if(board[y][x+1]!=0 && d[y][x+1]>-hy+1) {
d[y][x+1]=-hy+1;
q.push(make_pair(hy-1,make_pair(x+1,y)));
}
if(board[y-1][x]!=0 && d[y-1][x]>-hy+1){
d[y-1][x]=-hy+1;
q.push(make_pair(hy-1,make_pair(x,y-1)));
}
if(board[y+1][x]!=0 && d[y+1][x]>-hy+1){
d[y+1][x]=-hy+1;
q.push(make_pair(hy-1,make_pair(x,y+1)));
}
}
if(count!=pos.size()){
possible=false;
break;
}
}
if(!possible){
puts("-1");
continue;
}
/*
for(int i=0;i<pos.size();i++){
for(int j=0;j<pos.size();j++){
printf("%3d",dist[i][j]);
}
printf("\n");
}
*/
//traveling salesman problem
vector<int> v(pos.size()-1);
int ans=100000;
for(int i=0;i<pos.size()-1;i++) v[i]=i+1;
do{
int tmp=dist[0][v[0]];
for(int i=0;i<pos.size()-2;i++){
tmp+=dist[v[i]][v[i+1]];
if(tmp>ans){
sort(&v[i+1],&v[pos.size()-2],greater<int>());
break;
}
}
if(ans>tmp) ans=tmp;
}while(next_permutation(v.begin(),v.end()));
printf("%d\n",ans);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:16:7: error: 'gets' was not declared in this scope; did you mean 'getw'?
16 | gets(&board[i][1]);
| ^~~~
| getw
|
s092576262 | p00721 | C++ | #include <iostream>
#include <string>
#include <queue>
using namespace std;
int w, h;
string b[20];
int step[20][20];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
void bfs(int x, int y){
memset(step, -1, sizeof(step));
queue< pair<int, int> > qu; qu.push(make_pair(x,y));
step[x][y] = 0;
while(!qu.empty()){
pair<int, int> pr = qu.front(); qu.pop();
int cx = pr.first, cy = pr.second;
for(int i=0;i<4;i++){
int nx = cx+dx[i], ny = cy+dy[i];
if(nx<0||h<=nx||ny<0||w<=ny||b[nx][ny]=='x'||step[nx][ny]!=-1) continue;
step[nx][ny] = step[cx][cy]+1;
qu.push(make_pair(nx,ny));
}
}
}
int main(){
int c[11][11];
while(cin >> w >> h, w){
for(int i=0;i<h;i++) cin >> b[i];
vector<int> x(1), y(1);
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(b[i][j]=='o') x[0] = i, y[0] = j;
if(b[i][j]=='*') x.push_back(i), y.push_back(j);
}
}
int res = 1000000000;
for(int i=0;i<x.size();i++){
bfs(x[i], y[i]);
for(int j=0;j<x.size();j++){
c[i][j] = step[x[j]][y[j]];
if(c[i][j]==-1) res = -1;
}
}
vector<int> a(x.size()-1);
for(int i=0;i<x.size()-1;i++) a[i] = i+1;
do{
int cur = c[0][a[0]];
for(int i=0;i+1<a.size();i++) cur += c[a[i]][a[i+1]];
res = min(res, cur);
}while(next_permutation(a.begin(), a.end()));
cout << res << endl;
}
} | a.cc: In function 'void bfs(int, int)':
a.cc:15:9: error: 'memset' was not declared in this scope
15 | memset(step, -1, sizeof(step));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <queue>
+++ |+#include <cstring>
4 |
a.cc: In function 'int main()':
a.cc:55:24: error: 'next_permutation' was not declared in this scope
55 | }while(next_permutation(a.begin(), a.end()));
| ^~~~~~~~~~~~~~~~
|
s073114197 | p00721 | C++ | #include <iostream>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
int w, h;
string b[20];
int step[20][20];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
void bfs(int x, int y){
memset(step, -1, sizeof(step));
queue< pair<int, int> > qu; qu.push(make_pair(x,y));
step[x][y] = 0;
while(!qu.empty()){
pair<int, int> pr = qu.front(); qu.pop();
int cx = pr.first, cy = pr.second;
for(int i=0;i<4;i++){
int nx = cx+dx[i], ny = cy+dy[i];
if(nx<0||h<=nx||ny<0||w<=ny||b[nx][ny]=='x'||step[nx][ny]!=-1) continue;
step[nx][ny] = step[cx][cy]+1;
qu.push(make_pair(nx,ny));
}
}
}
int main(){
int c[11][11];
while(cin >> w >> h, w){
for(int i=0;i<h;i++) cin >> b[i];
vector<int> x(1), y(1);
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(b[i][j]=='o') x[0] = i, y[0] = j;
if(b[i][j]=='*') x.push_back(i), y.push_back(j);
}
}
int res = 1000000000;
for(int i=0;i<x.size();i++){
bfs(x[i], y[i]);
for(int j=0;j<x.size();j++){
c[i][j] = step[x[j]][y[j]];
if(c[i][j]==-1) res = -1;
}
}
vector<int> a(x.size()-1);
for(int i=0;i<x.size()-1;i++) a[i] = i+1;
do{
int cur = c[0][a[0]];
for(int i=0;i+1<a.size();i++) cur += c[a[i]][a[i+1]];
res = min(res, cur);
}while(next_permutation(a.begin(), a.end()));
cout << res << endl;
}
} | a.cc: In function 'void bfs(int, int)':
a.cc:16:9: error: 'memset' was not declared in this scope
16 | memset(step, -1, sizeof(step));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <algorithm>
+++ |+#include <cstring>
5 |
|
s473782760 | p00721 | C++ |
#include <iostream>
#include <string>
#include <queue>
using namespace std;
const int INF = 9999999;
int w, h;
string b[20];
int d[20][20];
char dx[] = {-1,1,0,0};
char dy[] = {0,0,-1,1};
void dist(int sx, int sy){
for(int i=0;i<20;i++)
for(int j=0;j<20;j++)
d[i][j] = INF;
queue< pair<int,int> > qu;
qu.push(make_pair(sx,sy));
d[sy][sx] = 0;
while(!qu.empty()){
pair<int, int> p = qu.front(); qu.pop();
int x = p.first, y = p.second;
for(int i=0;i<4;i++){
int nx = x + dx[i], ny = y + dy[i];
if(nx<0||nx>=w||ny<0||ny>=h||b[ny][nx]=='x') continue;
if(d[ny][nx] != INF) continue;
d[ny][nx] = d[y][x] + 1;
qu.push(make_pair(nx,ny));
}
}
}
int main(){
int c[11][11];
int x[11], y[11];
int ans[1<<11][11];
while(cin >> w >> h){
if(!(w||h)) break;
int num = 1;
for(int i=0;i<h;i++){
cin >> b[i];
for(int j=0;j<w;j++){
if(b[i][j]=='o') x[0] = j, y[0] = i;
if(b[i][j]=='*') x[num] = j, y[num++] = i;
}
}
bool flag = false;
memset(c,0,sizeof(c));
dist(x[0],y[0]);
for(int i=1;i<num;i++){
c[0][i] = d[y[i]][x[i]];
if(c[0][i] == INF) flag = true;
}
if(flag) { cout << -1 << endl; continue; }
for(int i=1;i<num;i++){
dist(x[i],y[i]);
for(int j=0;j<num;j++){
if(i==j) continue;
c[i][j] = d[y[j]][x[j]];
}
}
for(int i=0;i<(1<<num);i++) for(int j=0;j<num;j++) ans[i][j] = INF;
ans[1][0] = 0;
for(int i=0;i<(1<<num);i++){
for(int j=0;j<num;j++)
if((i>>j)&1)
for(int k=0;k<num;k++)
ans[i|(1<<k)][k] = min(ans[i|(1<<k)][k],ans[i][j]+c[j][k]);
}
int cost = INF;
for(int i=1;i<num;i++) cost = min(cost, ans[(1<<num)-1][i]);
cout << cost << endl;
} | a.cc: In function 'int main()':
a.cc:52:17: error: 'memset' was not declared in this scope
52 | memset(c,0,sizeof(c));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <queue>
+++ |+#include <cstring>
5 |
a.cc:77:10: error: expected '}' at end of input
77 | }
| ^
a.cc:37:11: note: to match this '{'
37 | int main(){
| ^
|
s514647540 | p00721 | C++ | #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 <cfloat>
using namespace std;
int INF = INT_MAX / 4;
int calculateDist(vector<string>& tile, int y1, int x1, int y2, int x2)
{
int h = tile.size();
int w = tile[0].size();
vector<vector<int> > minDist(h, vector<int>(w, INF));
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
queue<pair<int, int> > q;
q.push(make_pair(y1, x1));
minDist[y1][x1] = 0;
while(!q.empty()){
int y0 = q.front().first;
int x0 = q.front().second;
q.pop();
for(int i=0; i<4; ++i){
int y = y0 + dy[i];
int x = x0 + dx[i];
if(tile[y][x] != 'x' && minDist[y][x] == INF){
minDist[y][x] = minDist[y0][x0] + 1;
if(y == y2 && x == x2)
return minDist[y][x];
q.push(make_pair(y, x));
}
}
}
return INF;
}
int solve(vector<string>& tile)
{
int h = tile.size();
int w = tile[0].size();
int sy, sx;
vector<int> y, x;
for(int i=0; i<h; ++i){
for(int j=0; j<w; ++j){
if(tile[i][j] == 'o'){
sy = i;
sx = j;
}
if(tile[i][j] == '*'){
y.push_back(i);
x.push_back(j);
}
}
}
int n = y.size();
vector<vector<int> > dist(n, vector<int>(n, 0));
for(int i=0; i<n; ++i){
for(int j=i+1; j<n; ++j){
dist[i][j] = dist[j][i] = calculateDist(tile, y[i], x[i], y[j], x[j]);
}
}
vector<vector<int> > minDist(n, vector<int>(1<<n, INF));
for(int i=0; i<n; ++i){
minDist[i][1<<i] = calculateDist(tile, sy, sx, y[i], x[i]);
}
for(int i=0; i<(1<<n); ++i){
bitset<10> bs(i);
for(int j=0; j<n; ++j){
for(int k=0; k<n; ++k){
if(bs[k])
continue;
bs[k] = true;
minDist[k][bs.to_ulong()] = min(minDist[k][bs.to_ulong()], minDist[j][i] + dist[j][k]);
bs[k] = false;
}
}
}
int ret = INF;
for(int i=0; i<n; ++i){
ret = min(ret, minDist[i][(1<<n)-1]);
}
if(ret == INF)
return -1;
return ret;
}
int main()
{
for(;;){
int w, h;
cin >> w >> h;
if(w == 0)
break;
vector<string> tile(h+2);
tile[0] = tile[h+1] = string(w+2, 'x');
for(int i=1; i<=h; ++i){
cin >> tile[i];
tile[i] = 'x' + tile[i] + 'x';
}
cout << solve(tile) << endl;
}
} | a.cc:18:11: error: 'INT_MAX' was not declared in this scope
18 | int INF = INT_MAX / 4;
| ^~~~~~~
a.cc:16:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
15 | #include <cfloat>
+++ |+#include <climits>
16 | using namespace std;
|
s358000196 | p00721 | C++ | #include<iostream>
#define MAX_V 20
#define INF 10000000
#include<queue>
#include<string>
#include<map>
#include<vector>
using namespace std;
struct edge{
int to,cost;
};
int co[MAX_V][MAX_V];
int h,w,V,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
string s[1000];
typedef pair<int,int> P;
map<P,int> mp;
int dp[1 << MAX_V][MAX_V];
int rec(int S,int v){
if(dp[S][v]>=0)
return dp[S][v];
if(S==(1<<V)-2){
return dp[S][v]=0;
}
int res=INF;
for(int u=0;u<V;u++){
if(!(S>>u&1)){
res=min(res,rec(S|1<<u,u)+co[v][u]);
}
}
return dp[S][v]=res;
}
void solve(){
memset(dp,-1,sizeof(dp));
int temp=rec(0,0);
if(temp==INF)
cout<<-1<<endl;
else
cout<<temp<<endl;
}
void func(int y,int x,int q){
int d[MAX_V][MAX_V];
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
d[i][j]=INF;
d[y][x]=0;
queue<P> box;
box.push(P(y,x));
while(!box.empty()){
int nx,ny,sx,sy;
P pre=box.front();
box.pop();
sy=pre.first;
sx=pre.second;
for(int i=0;i<4;i++){
nx=sx+dx[i];
ny=sy+dy[i];
if((nx>=0&&ny>=0&&nx<w&&ny<h)&&(s[ny][nx]=='o'||s[ny][nx]=='.'||s[ny][nx]=='*')&&(d[ny][nx]==INF)){
box.push(P(ny,nx));
if(s[ny][nx]=='*'||s[ny][nx]=='o'){
co[mp[P(ny,nx)]][q]=d[sy][sx]+1;
co[q][mp[P(ny,nx)]]=d[sy][sx]+1;
}
d[ny][nx]=d[sy][sx]+1;
}
}
}
}
int main(){
while(cin>>w>>h,h||w){
V=1;
for(int i=0;i<h;i++)
cin>>s[i];
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
if(s[i][j]=='o')
mp[P(i,j)]=0;
else if(s[i][j]=='*'){
mp[P(i,j)]=V;
V++;
}
for(int i=0;i<V;i++)
for(int j=0;j<V;j++){
co[i][j]=INF;
for(int i=0;i<h;i++)
for(int j=0;j<w;j++){
if(s[i][j]=='o'){
func(i,j,0);
}else if(s[i][j]=='*'){
func(i,j,mp[P(i,j)]);
}
}
}
solve();
}
return 0;
} | a.cc: In function 'void solve()':
a.cc:33:9: error: 'memset' was not declared in this scope
33 | memset(dp,-1,sizeof(dp));
| ^~~~~~
a.cc:7:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
6 | #include<map>
+++ |+#include <cstring>
7 | #include<vector>
|
s974759866 | p00721 | C++ | #include <iostream>
#include <vector>
#include <string>
using namespace std;
struct P{
int x,y;
} s;
int w, h;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
int to[12][12];
int cnt[21][21];
string f[21];
void solve(int x, int y, int cnt_,int from ,vector<struct P>& vc){
for(int i=0 ; i<4 ; i++ ){
int mx = x + dx[i];
int my = y + dy[i];
if( mx < 0 || my < 0 || mx >= w || my >= h ){
continue;
}else if( cnt[my][mx] == -1 ){
continue;
}else if( cnt[my][mx] > cnt_ ){
cnt[my][mx] = cnt_;
if( f[my][mx] == '.' ){
solve( mx , my , cnt_+1 , from , vc );
}else if( f[my][mx] == '*' ){
for(int j=0 ; j < (int)vc.size() ; j++ ){
if( vc[j].x == mx && vc[j].y == my ){
to[from][j+1] = cnt_;
to[j+1][from] = cnt_;
break;
}
}
}
}
}
}
/*
void debug(int x,int y,char c){
cout << c << ":(x,y) = (" << x << "," << y << ")\n";
}*/
int main(){
while( cin >> w >> h , w||h ){
vector<struct P> vc;
for(int y=0 ; y<12 ; y++ ){
for(int x=0 ; x<12 ; x++ ){
to[y][x] = 1000;
}
}
for(int y=0 ; y < h ; y++ ){
cin >> f[y];
for(int x=0 ; x < w ; x++ ){
if( f[y][x] == 'o' ){
cnt[y][x] = -1;
s.x = x, s.y = y;
}else if( f[y][x] == '*' ){
struct P p;
p.x = x, p.y = y;
vc.push_back( p );
}else if( f[y][x] == 'x' ){
cnt[y][x] = -1;
}
}
}
for(int i=0 ; i <= (int)vc.size() ; i++ ){
for(int y=0 ; y<21 ; y++ )
for(int x=0 ; x<21 ; x++ )
if( cnt[y][x] != -1 )
cnt[y][x] = 1000;
if( i > 0 ){
cnt[ vc[i-1].y ][ vc[i-1].x ] = -1;
solve( vc[i-1].x , vc[i-1].y , 1 , i , vc );
}else{
solve( s.x , s.y , 1 , i , vc );
}
}
vector<int> vc_;
bool flag = true;
int ans = 10000000;
for(int i=0 ; i < (int)vc.size() ; i++ )
vc_.push_back( i+1 );
do{
int ans_ = 0;
for(int i=0 ; i < (int)vc_.size() ; i++ ){
//cout << "+ : " << to[ ((i==0)? 0 : vc_[i-1]) ][ vc_[i] ] << " ";
if( to[ ((i==0)? 0 : vc_[i-1]) ][ vc_[i] ] == 1000 ){
flag = false;
break;
}else{
ans_ += to[ ((i==0)? 0 : vc_[i-1]) ][ vc_[i] ];
}
}
ans = min( ans_ , ans );
}while( next_permutation( vc_.begin() , vc_.end() ) && flag );
//cout << endl;
/*debug( s.x , s.y , 'S' );
for(int i=0 ; i < (int)vc.size() ; i++ ){
debug( vc[i].x , vc[i].y , i+'0' );
//cout << "start => " << to[0][i+1] << endl;
}
for(int y=0 ; y <= (int)vc.size() ; y++ ){
for(int x=0 ; x <= (int)vc.size() ; x++ ){
cout << to[y][x] << " ";
}
cout << endl;
}*/
cout << ( (flag)? ans : -1 ) << endl;
}
} | a.cc: In function 'int main()':
a.cc:102:25: error: 'next_permutation' was not declared in this scope
102 | }while( next_permutation( vc_.begin() , vc_.end() ) && flag );
| ^~~~~~~~~~~~~~~~
|
s653534574 | p00721 | C++ | #include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct Point {
int x, y;
Point(int x, int y) : x(x), y(y) {;}
};
typedef pair<int, Point> State;
int W, H, C, INF = (1 << 22);
vector<Point> pos;
char field[20][20];
int dist[11][11];
int dx[4] = {0, 1, 0, -1},
dy[4] = {-1, 0, 1, 0};
int dp[1 << 11][11];
void bfs(int src)
{
int d[20][20];
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
d[i][j] = INF;
Point start = pos[src];
queue<State> que;
que.push(State(0, start));
while (!que.empty()) {
State s = que.front(); que.pop();
Point p = s.second;
if (d[p.y][p.x] != INF) continue;
d[p.y][p.x] = s.first;
for (int k = 0; k < 4; k++) {
int nx = p.x + dx[k], ny = p.y + dy[k];
if (nx >= 0 && nx < W && ny >= 0 && ny < H && field[ny][nx] != 'x') {
que.push(State(s.first + 1, Point(nx, ny)));
}
}
}
for (int dst = 0; dst < C; dst++)
if (dst != src)
dist[src][dst] = d[pos[dst].y][pos[dst].x];
}
int rec(int S, int v)
{
// 訪問済み
if (dp[S][v] >= 0)
return dp[S][v];
// すべての頂点を訪れて戻ってきた
if (S == (1 << C) - 1) {
return dp[S][v] = 0;
}
int res = INF;
for (int u = 0; u < C; u++) {
if (!(S >> u & 1)) {
// uが未訪問なので、uへ移動
res = min(res, rec(S | 1 << u, u) + dist[v][u]);
}
}
return dp[S][v] = res;
}
void solve()
{
// 距離テーブルの初期化
for (int i = 0; i < C; i++)
for (int j = 0; j < C; j++)
if (i == j)
dist[i][j] = 0;
else
dist[i][j] = INF;
// 全点間の距離を求める
for (int src = 0; src < C; src++)
bfs(src);
// TSP
memset(dp, -1, sizeof(dp));
int res = rec(0, 0);
if (res >= INF)
cout << -1 << endl;
else
cout << res << endl;
}
int main()
{
while (cin >> W >> H && (W && H)) {
// スタート+汚れたタイルの数
C = 1;
pos.clear();
pos.push_back(Point(-1, -1));
// read
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> field[i][j];
if (field[i][j] == '*') {
pos.push_back(Point(j, i));
C++;
} else if (field[i][j] == 'o') {
pos[0].x = j;
pos[0].y = i;
}
}
}
solve();
}
} | a.cc: In function 'void solve()':
a.cc:91:3: error: 'memset' was not declared in this scope
91 | memset(dp, -1, sizeof(dp));
| ^~~~~~
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 |
|
s001809797 | p00721 | C++ | #include <iostream>
#include <vector>
#include <queue>
#include <cstdlib>
using namespace std;
struct Point {
int x, y;
Point(int x, int y) : x(x), y(y) {;}
};
typedef pair<int, Point> State;
int W, H, C, INF = (1 << 22);
vector<Point> pos;
char field[20][20];
int dist[11][11];
int dx[4] = {0, 1, 0, -1},
dy[4] = {-1, 0, 1, 0};
int dp[1 << 11][11];
void bfs(int src)
{
int d[20][20];
for (int i = 0; i < H; i++)
for (int j = 0; j < W; j++)
d[i][j] = INF;
Point start = pos[src];
queue<State> que;
que.push(State(0, start));
while (!que.empty()) {
State s = que.front(); que.pop();
Point p = s.second;
if (d[p.y][p.x] != INF) continue;
d[p.y][p.x] = s.first;
for (int k = 0; k < 4; k++) {
int nx = p.x + dx[k], ny = p.y + dy[k];
if (nx >= 0 && nx < W && ny >= 0 && ny < H && field[ny][nx] != 'x') {
que.push(State(s.first + 1, Point(nx, ny)));
}
}
}
for (int dst = 0; dst < C; dst++)
if (dst != src)
dist[src][dst] = d[pos[dst].y][pos[dst].x];
}
int rec(int S, int v)
{
// 訪問済み
if (dp[S][v] >= 0)
return dp[S][v];
// すべての頂点を訪れて戻ってきた
if (S == (1 << C) - 1) {
return dp[S][v] = 0;
}
int res = INF;
for (int u = 0; u < C; u++) {
if (!(S >> u & 1)) {
// uが未訪問なので、uへ移動
res = min(res, rec(S | 1 << u, u) + dist[v][u]);
}
}
return dp[S][v] = res;
}
void solve()
{
// 距離テーブルの初期化
for (int i = 0; i < C; i++)
for (int j = 0; j < C; j++)
if (i == j)
dist[i][j] = 0;
else
dist[i][j] = INF;
// 全点間の距離を求める
for (int src = 0; src < C; src++)
bfs(src);
// TSP
memset(dp, -1, sizeof(dp));
int res = rec(0, 0);
if (res >= INF)
cout << -1 << endl;
else
cout << res << endl;
}
int main()
{
while (cin >> W >> H && (W && H)) {
// スタート+汚れたタイルの数
C = 1;
pos.clear();
pos.push_back(Point(-1, -1));
// read
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> field[i][j];
if (field[i][j] == '*') {
pos.push_back(Point(j, i));
C++;
} else if (field[i][j] == 'o') {
pos[0].x = j;
pos[0].y = i;
}
}
}
solve();
}
} | a.cc: In function 'void solve()':
a.cc:92:3: error: 'memset' was not declared in this scope
92 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <cstdlib>
+++ |+#include <cstring>
5 |
|
s700898764 | p00721 | C++ | #include<iostream>
#include<queue>
#include<algorithm>
#define MAX 20
#define DMAX 10
using namespace std;
class Point{
public:
int y, x;
Point(){}
Point( int y, int x ): y(y), x(x){}
bool operator == ( const Point &p ) const{
return ( x == p.x && y == p.y );
}
};
int W, H;
char G[MAX][MAX];
Point start;
Point dirty[DMAX];
int dsize;
int T[DMAX]; // start to all dirty;
int M[DMAX][DMAX]; // all dirty to all dirty
int bfs( Point p1, Point p2 ){
bool visited[MAX][MAX];
int d[MAX][MAX];
queue<Point> q;
for ( int i = 0; i < H; i++ ){
for ( int j = 0; j < W; j++ ){
visited[i][j] = false;
d[i][j] = INT_MAX;
}
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
q.push( p1 );
d[p1.y][p1.x] = 0;
Point u;
while ( !q.empty() ){
u = q.front(); q.pop();
if ( u == p2 ) return d[u.y][u.x];
int nx, ny;
for ( int r = 0; r < 4; r++ ){
ny = u.y + dy[r];
nx = u.x + dx[r];
if ( !( 0 <= nx && 0 <= ny && ny < H && nx < W ) ) continue;
if ( !visited[ny][nx] && G[ny][nx] != 'x' ){
visited[ny][nx] = true;
d[ny][nx] = d[u.y][u.x] + 1;
q.push( Point( ny, nx ) );
}
}
}
return INT_MAX;
}
void computeDistanceTable(){
for ( int i = 0; i < dsize; i++ ){
T[i] = bfs( start, dirty[i]);
}
for ( int i = 0; i < dsize-1; i++ ){
for ( int j = i; j < dsize; j++ ){
if ( i == j ) M[i][j] = M[j][i] = 0;
M[i][j] = M[j][i] = bfs( dirty[i], dirty[j] );
}
}
}
int getMinimumMove(){
int order[DMAX];
for ( int i = 0; i < dsize; i++ ){
order[i] = i;
}
int minMove = INT_MAX;
do{
int move = T[ order[0] ];
for ( int i = 1; i < dsize; i++ ){
move += M[ order[i-1] ][ order[i] ];
}
if ( minMove > move ) minMove = move;
} while( next_permutation(order, order + dsize )) ;
return minMove;
}
bool notReachable(){
for ( int i = 0; i < dsize; i++ ){
if ( T[i] == INT_MAX ) return true;
}
return false;
}
void compute(){
computeDistanceTable();
if ( notReachable() ) cout << "-1" << endl;
else {
cout << getMinimumMove() << endl;
}
}
bool read(){
cin >> W >> H;
if ( W == 0 && H == 0 ) return false;
dsize = 0;
char ch;
for ( int i = 0; i < H; i++ ){
for ( int j = 0; j < W; j++ ){
cin >> ch;
G[i][j] = ch;
if ( ch == 'o' ){
start = Point(i, j);
} else if ( ch == '*' ){
dirty[dsize++] = Point(i, j);
}
}
}
return true;
}
main(){
while ( read() ) compute();
return 0;
} | a.cc: In function 'int bfs(Point, Point)':
a.cc:34:23: error: 'INT_MAX' was not declared in this scope
34 | d[i][j] = 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 | #define MAX 20
a.cc:66:12: error: 'INT_MAX' was not declared in this scope
66 | return INT_MAX;
| ^~~~~~~
a.cc:66:12: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: In function 'int getMinimumMove()':
a.cc:87:19: error: 'INT_MAX' was not declared in this scope
87 | int minMove = INT_MAX;
| ^~~~~~~
a.cc:87:19: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: In function 'bool notReachable()':
a.cc:105:22: error: 'INT_MAX' was not declared in this scope
105 | if ( T[i] == INT_MAX ) return true;
| ^~~~~~~
a.cc:105:22: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: At global scope:
a.cc:137:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
137 | main(){
| ^~~~
|
s082663521 | p00721 | C++ | #include<iostream>
#include<queue>
#include<algorithm>
#define MAX 20
#define DMAX 10
using namespace std;
class Point{
public:
int y, x;
Point(){}
Point( int y, int x ): y(y), x(x){}
bool operator == ( const Point &p ) const{
return ( x == p.x && y == p.y );
}
};
int W, H;
char G[MAX][MAX];
Point start;
Point dirty[DMAX];
int dsize;
int T[DMAX]; // start to all dirty;
int M[DMAX][DMAX]; // all dirty to all dirty
int bfs( Point p1, Point p2 ){
bool visited[MAX][MAX];
int d[MAX][MAX];
queue<Point> q;
for ( int i = 0; i < H; i++ ){
for ( int j = 0; j < W; j++ ){
visited[i][j] = false;
d[i][j] = INT_MAX;
}
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
q.push( p1 );
d[p1.y][p1.x] = 0;
Point u;
while ( !q.empty() ){
u = q.front(); q.pop();
if ( u == p2 ) return d[u.y][u.x];
int nx, ny;
for ( int r = 0; r < 4; r++ ){
ny = u.y + dy[r];
nx = u.x + dx[r];
if ( !( 0 <= nx && 0 <= ny && ny < H && nx < W ) ) continue;
if ( !visited[ny][nx] && G[ny][nx] != 'x' ){
visited[ny][nx] = true;
d[ny][nx] = d[u.y][u.x] + 1;
q.push( Point( ny, nx ) );
}
}
}
return INT_MAX;
}
void computeDistanceTable(){
for ( int i = 0; i < dsize; i++ ){
T[i] = bfs( start, dirty[i]);
}
for ( int i = 0; i < dsize-1; i++ ){
for ( int j = i; j < dsize; j++ ){
if ( i == j ) M[i][j] = M[j][i] = 0;
M[i][j] = M[j][i] = bfs( dirty[i], dirty[j] );
}
}
}
int getMinimumMove(){
int order[DMAX];
for ( int i = 0; i < dsize; i++ ){
order[i] = i;
}
int minMove = INT_MAX;
do{
int move = T[ order[0] ];
for ( int i = 1; i < dsize; i++ ){
move += M[ order[i-1] ][ order[i] ];
}
if ( minMove > move ) minMove = move;
} while( next_permutation(order, order + dsize )) ;
return minMove;
}
bool notReachable(){
for ( int i = 0; i < dsize; i++ ){
if ( T[i] == INT_MAX ) return true;
}
return false;
}
void compute(){
computeDistanceTable();
if ( notReachable() ) cout << "-1" << endl;
else {
cout << getMinimumMove() << endl;
}
}
bool read(){
cin >> W >> H;
if ( W == 0 && H == 0 ) return false;
dsize = 0;
char ch;
for ( int i = 0; i < H; i++ ){
for ( int j = 0; j < W; j++ ){
cin >> ch;
G[i][j] = ch;
if ( ch == 'o' ){
start = Point(i, j);
} else if ( ch == '*' ){
dirty[dsize++] = Point(i, j);
}
}
}
return true;
}
main(){
while ( read() ) compute();
} | a.cc: In function 'int bfs(Point, Point)':
a.cc:34:23: error: 'INT_MAX' was not declared in this scope
34 | d[i][j] = 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 | #define MAX 20
a.cc:66:12: error: 'INT_MAX' was not declared in this scope
66 | return INT_MAX;
| ^~~~~~~
a.cc:66:12: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: In function 'int getMinimumMove()':
a.cc:87:19: error: 'INT_MAX' was not declared in this scope
87 | int minMove = INT_MAX;
| ^~~~~~~
a.cc:87:19: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: In function 'bool notReachable()':
a.cc:105:22: error: 'INT_MAX' was not declared in this scope
105 | if ( T[i] == INT_MAX ) return true;
| ^~~~~~~
a.cc:105:22: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc: At global scope:
a.cc:137:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
137 | main(){
| ^~~~
|
s938729061 | p00721 | C++ | /*********************
AOJ_1140
Cleaning Robot
*********************/
#include <iostream>
#include <queue>
#include <string>
using namespace std;
//構造体宣言
struct pos{
int x; //座標
int y;
int dis; //距離
};
int main(){
int w, h;
while(1){
cin >> w >> h;
if(w == 0 || h == 0) break;
//タイルの初期化
char tile[30][30];
for(int i = 0; i < 30; i ++){
for(int j = 0; j < 30; j++){
tile[i][j] = 'x';
}
}
//タイルの入力
int stain = 0; //汚れの数
queue<pos> que;
for(int i = 1; i <= h; i++){
string input;
cin >> input;
for(int j = 1; j <= w; j++){
tile[i][j] = input[j-1];
if(tile[i][j] == '*') stain++;
if(tile[i][j] == 'o'){
pos p;
p.y = i; p.x = j;
p.dis = 0;
que.push(p);
tile[i][j] = '.';
}
}
}
int count = 0;
while(stain > 0){
char bfs[30][30];
memcpy(bfs, tile, sizeof(bfs));
pos p = que.front();
bfs[p.y][p.x] = 0;
int x1[] = {-1, 0, 1, 0}, y1[] = {0, -1, 0, 1};
int f = 1;
while(f && !que.empty()){
pos p1 = que.front();
que.pop();
for(int i = 0; i < 4; i++){
p = p1;
p.x += x1[i]; p.y += y1[i];
if(bfs[p.y][p.x] == '.'){
p.dis++;
bfs[p.y][p.x] = p.dis;
que.push(p);
}else if(bfs[p.y][p.x] == '*'){
count += p.dis+1;
stain--;
tile[p.y][p.x] == '.';
while(!que.empty()) que.pop();
p.dis = 0;
que.push(p);
f = 0;
break;
}
}
}
if(que.empty()) break;
}
if(stain > 0) cout << "-1" << endl;
else cout << count << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:52:25: error: 'memcpy' was not declared in this scope
52 | memcpy(bfs, tile, sizeof(bfs));
| ^~~~~~
a.cc:7:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
6 | #include <queue>
+++ |+#include <cstring>
7 | #include <string>
|
s612758482 | p00721 | C++ | /*********************
AOJ_1140
Cleaning Robot
*********************/
#include <iostream>
#include <queue>
#include <string>
#include <cstdio>
using namespace std;
//構造体宣言
struct pos{
int x; //座標
int y;
int dis; //距離
};
int main(){
int w, h;
while(1){
cin >> w >> h;
if(w == 0 || h == 0) break;
//タイルの初期化
char tile[30][30];
for(int i = 0; i < 30; i ++){
for(int j = 0; j < 30; j++){
tile[i][j] = 'x';
}
}
//タイルの入力
int stain = 0; //汚れの数
queue<pos> que;
for(int i = 1; i <= h; i++){
string input;
cin >> input;
for(int j = 1; j <= w; j++){
tile[i][j] = input[j-1];
if(tile[i][j] == '*') stain++;
if(tile[i][j] == 'o'){
pos p;
p.y = i; p.x = j;
p.dis = 0;
que.push(p);
tile[i][j] = '.';
}
}
}
int count = 0;
while(stain > 0){
char bfs[30][30];
memcpy(bfs, tile, sizeof(bfs));
pos p = que.front();
bfs[p.y][p.x] = 0;
int x1[] = {-1, 0, 1, 0}, y1[] = {0, -1, 0, 1};
int f = 1;
while(f && !que.empty()){
pos p1 = que.front();
que.pop();
for(int i = 0; i < 4; i++){
p = p1;
p.x += x1[i]; p.y += y1[i];
if(bfs[p.y][p.x] == '.'){
p.dis++;
bfs[p.y][p.x] = p.dis;
que.push(p);
}else if(bfs[p.y][p.x] == '*'){
count += p.dis+1;
stain--;
tile[p.y][p.x] == '.';
while(!que.empty()) que.pop();
p.dis = 0;
que.push(p);
f = 0;
break;
}
}
}
if(que.empty()) break;
}
if(stain > 0) cout << "-1" << endl;
else cout << count << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:53:25: error: 'memcpy' was not declared in this scope
53 | memcpy(bfs, tile, sizeof(bfs));
| ^~~~~~
a.cc:9:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
8 | #include <cstdio>
+++ |+#include <cstring>
9 | using namespace std;
|
s198721666 | p00721 | C++ | /*********************
AOJ_1140
Cleaning Robot
*********************/
#include <iostream>
#include <queue>
#include <string>
#include <string>
using namespace std;
//構造体宣言
struct pos{
int x; //座標
int y;
int dis; //距離
};
int main(){
int w, h;
while(1){
cin >> w >> h;
if(w == 0 || h == 0) break;
//タイルの初期化
char tile[30][30];
for(int i = 0; i < 30; i ++){
for(int j = 0; j < 30; j++){
tile[i][j] = 'x';
}
}
//タイルの入力
int stain = 0; //汚れの数
queue<pos> que;
for(int i = 1; i <= h; i++){
string input;
cin >> input;
for(int j = 1; j <= w; j++){
tile[i][j] = input[j-1];
if(tile[i][j] == '*') stain++;
if(tile[i][j] == 'o'){
pos p;
p.y = i; p.x = j;
p.dis = 0;
que.push(p);
tile[i][j] = '.';
}
}
}
int count = 0;
while(stain > 0){
char bfs[30][30];
memcpy(bfs, tile, sizeof(bfs));
pos p = que.front();
bfs[p.y][p.x] = 0;
int x1[] = {-1, 0, 1, 0}, y1[] = {0, -1, 0, 1};
int f = 1;
while(f && !que.empty()){
pos p1 = que.front();
que.pop();
for(int i = 0; i < 4; i++){
p = p1;
p.x += x1[i]; p.y += y1[i];
if(bfs[p.y][p.x] == '.'){
p.dis++;
bfs[p.y][p.x] = p.dis;
que.push(p);
}else if(bfs[p.y][p.x] == '*'){
count += p.dis+1;
stain--;
tile[p.y][p.x] == '.';
while(!que.empty()) que.pop();
p.dis = 0;
que.push(p);
f = 0;
break;
}
}
}
if(que.empty()) break;
}
if(stain > 0) cout << "-1" << endl;
else cout << count << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:53:25: error: 'memcpy' was not declared in this scope
53 | memcpy(bfs, tile, sizeof(bfs));
| ^~~~~~
a.cc:7:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
6 | #include <queue>
+++ |+#include <cstring>
7 | #include <string>
|
s288874878 | p00722 | Java | import java.util.Arrays;
import java.util.Scanner;
public class Eratosthenes {
//途中
int prime[];
void eratosthenes(int max) {
prime = new int[max + 1];
Arrays.fill(prime, 1);
prime[0] = prime[1] = 0;
for (int i = 2; i * i <= max; i++) {
if (prime[i] == 1) {
for (int j = i * i; j <= max; j += i) {
prime[j] = 0;
}
}
}
}
void eratosthenes2(int max) {
int end = max / 2 + 1;
prime = new int[end];
Arrays.fill(prime, 1);
prime[0] = 0;
for (int i = 0; (2 * i + 1) * (2 * i + 1) <= max; i++) {
if (prime[i] == 1) {
for (int j = 2 * i * (i + 1); j < end; j += 2 * i + 1) {
prime[j] = 0;
}
}
}
}
void eratosthenes3(int max) {
int end = max / 6 + 1;
prime = new int[end];
Arrays.fill(prime, 1);
prime[0] ^= 1;
for (int i = 0; (6 * i + 5) * (6 * i + 5) <= max; i++) {
}
}
boolean isPrime2(int n) {
if (n == 2) return true;
if (n % 2 == 0) return false;
n = (n - 1) / 2;
if (prime[n] == 1) return true;
return false;
}
void run() {
Scanner sc = new Scanner(System.in);
}
public static void main(String[] args) {
new Eratosthenes().run();
}
} | Main.java:4: error: class Eratosthenes is public, should be declared in a file named Eratosthenes.java
public class Eratosthenes {
^
1 error
|
s470295501 | p00722 | Java | import java.util.Scanner;
public class Main {
static boolean sosuu(int s) {
if(s == 1) return false;
for(int i=2; i*i<=s; i++) {
if(s%i == 0) return false;
}
return true;
}
public static void main(String[] args) {
try(Scanner sc = new Scanner(System.in)) {
while(sc.hasNext()) {
int a = sc.nextInt();
int d = sc.nextInt();
int n = sc.nextInt();
if(a+d+n == 0) break;
int sum = a;
int ans = a;
if(sosuu(a)) n--;
if(n != 0) {
for(int i=0;;i++) {
sum =+ d;
if(sosuu(sum)) n--;
if(n == 0) {
ans = sum;
break;
}
}
}
System.out.println(ans);
}
}
}
}
import java.util.Scanner;
public class Main {
static boolean sosuu(int s) {
if(s == 1) return false;
for(int i=2; i*i<=s; i++) {
if(s%i == 0) return false;
}
return true;
}
public static void main(String[] args) {
try(Scanner sc = new Scanner(System.in)) {
while(sc.hasNext()) {
int a = sc.nextInt();
int d = sc.nextInt();
int n = sc.nextInt();
if(a+d+n == 0) break;
int sum = a;
int ans = a;
if(sosuu(a)) n--;
if(n != 0) {
for(int i=0;;i++) {
sum =+ d;
if(sosuu(sum)) n--;
if(n == 0) {
ans = sum;
break;
}
}
}
System.out.println(ans);
}
}
}
}
| Main.java:38: error: class, interface, enum, or record expected
import java.util.Scanner;
^
1 error
|
s502538615 | p00722 | Java | import java.io.*;
import java.util.*;
import java.math.*;
class Main{
public static void main(String[] args){
BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
int[] prime = new int[1000000];
prime[0] = 1; prime[1] = 1;
for(int i=2; i<1000; i++)
if(prime[i]==0)
for(int j=i*i; j<1000000; j+=i)
prime[j]=1;
try {
while(true){
String[] st = sc.readLine().split(" ");
int a = Integer.valueOf(st[0]), d = Integer.valueOf(st[1]), n = Integer.valueOf(st[2]);
if(a==0 && b==0 && c==0)
break;
int check = 0;
while(check!=n){
if(prime[a]==0)
check++;
a+=d;
}
System.out.println(a-d);
}
}catch(Exception e){
System.out.println("Error");
}
}
} | Main.java:17: error: cannot find symbol
if(a==0 && b==0 && c==0)
^
symbol: variable b
location: class Main
Main.java:17: error: cannot find symbol
if(a==0 && b==0 && c==0)
^
symbol: variable c
location: class Main
2 errors
|
s557750020 | p00722 | Java | import java.util.*;
public class P1141__ {
public static void main(String[] args) {
int MAX = 1000000;
boolean[] p;
p = new boolean[MAX+1]; p[0] = p[1] = true;
for(int i=2;i<=MAX;i++) if(!p[i])
for(int j=i*2;j<=MAX;j+=i) p[j] = true;
Scanner sc = new Scanner(System.in);
for(;;) {
int a = sc.nextInt(), d = sc.nextInt(), n = sc.nextInt();
if( (a|d|n) == 0 ) break;
for(;n!=0;a+=d) if(!p[a])n--;
System.out.println(a-d);
}
}
} | Main.java:2: error: class P1141__ is public, should be declared in a file named P1141__.java
public class P1141__ {
^
1 error
|
s579572353 | p00722 | C | #include<stdio.h>
bool isprime(int n,int k=2){if(n==1){return false;}if(n<k*k){return true;}if(n%k==0){return false;}return isprime(n,k+1);}int main(){int a,d,n,c;while(true){scanf("%d%d%d",&n,&d,&a);if(n==0){break;}c=0;while(c<n){if(isprime(a)){c++;}a+=d;}printf("%d\n",a-d);}} | main.c:2:1: error: unknown type name 'bool'
2 | bool isprime(int n,int k=2){if(n==1){return false;}if(n<k*k){return true;}if(n%k==0){return false;}return isprime(n,k+1);}int main(){int a,d,n,c;while(true){scanf("%d%d%d",&n,&d,&a);if(n==0){break;}c=0;while(c<n){if(isprime(a)){c++;}a+=d;}printf("%d\n",a-d);}}
| ^~~~
main.c:2:1: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
1 | #include<stdio.h>
+++ |+#include <stdbool.h>
2 | bool isprime(int n,int k=2){if(n==1){return false;}if(n<k*k){return true;}if(n%k==0){return false;}return isprime(n,k+1);}int main(){int a,d,n,c;while(true){scanf("%d%d%d",&n,&d,&a);if(n==0){break;}c=0;while(c<n){if(isprime(a)){c++;}a+=d;}printf("%d\n",a-d);}}
main.c:2:25: error: expected ';', ',' or ')' before '=' token
2 | bool isprime(int n,int k=2){if(n==1){return false;}if(n<k*k){return true;}if(n%k==0){return false;}return isprime(n,k+1);}int main(){int a,d,n,c;while(true){scanf("%d%d%d",&n,&d,&a);if(n==0){break;}c=0;while(c<n){if(isprime(a)){c++;}a+=d;}printf("%d\n",a-d);}}
| ^
main.c: In function 'main':
main.c:2:152: error: 'true' undeclared (first use in this function)
2 | bool isprime(int n,int k=2){if(n==1){return false;}if(n<k*k){return true;}if(n%k==0){return false;}return isprime(n,k+1);}int main(){int a,d,n,c;while(true){scanf("%d%d%d",&n,&d,&a);if(n==0){break;}c=0;while(c<n){if(isprime(a)){c++;}a+=d;}printf("%d\n",a-d);}}
| ^~~~
main.c:2:152: note: 'true' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:2:152: note: each undeclared identifier is reported only once for each function it appears in
main.c:2:217: error: implicit declaration of function 'isprime' [-Wimplicit-function-declaration]
2 | bool isprime(int n,int k=2){if(n==1){return false;}if(n<k*k){return true;}if(n%k==0){return false;}return isprime(n,k+1);}int main(){int a,d,n,c;while(true){scanf("%d%d%d",&n,&d,&a);if(n==0){break;}c=0;while(c<n){if(isprime(a)){c++;}a+=d;}printf("%d\n",a-d);}}
| ^~~~~~~
|
s147229770 | p00722 | C | #include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define MAX 1000000
int main(){
int a,d,c,sosu;;
int m=0;
int n=0;
while(1){
scanf("%d%d%d",&a,&d,&c);
if(a==0&&d==0&&c==0){
break;
}
for(a=a;a<MAX;a+=d){
if(a==1){
continue;
}
if(a==2){
m++;
}
if(a%2!=0){
for(sosu=3;sosu<=sqrt(a);sosu++){
if(a%sosu==0){
n++;
break;
}
}
if(pre==0){
m++;
}
}
n=0;
if(m>=c){
break;
}
}
printf("%d\n",a);
m=0;
}
return 0;
} | main.c: In function 'main':
main.c:35:12: error: 'pre' undeclared (first use in this function)
35 | if(pre==0){
| ^~~
main.c:35:12: note: each undeclared identifier is reported only once for each function it appears in
|
s553110246 | p00722 | C | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int Prime(int p){
int i,f;
f = 0;
if(p == 1) return 0;
if(p == 2) return 1;
if(p % 2 == 0) return 0;
for(i=3;i*i <= p;i += 2){
if(p % i == 0) f = 1;
}
if(f == 0) return 1;
else return 0;
}
int main() {
int a,d,n;
int i,count;
while(1) {
scanf("%d %d %d",&a,&d,&n);
if(!a&&!d&&!n) break;
count=0,i=a;
while(count<n) {
if(prime(i)) {
count++;
}
i+=d;
//printf("%d\n",i);
}
printf("%d\n",i-d);
}
return 0;
} | main.c: In function 'main':
main.c:28:16: error: implicit declaration of function 'prime'; did you mean 'Prime'? [-Wimplicit-function-declaration]
28 | if(prime(i)) {
| ^~~~~
| Prime
|
s143609623 | p00722 | C | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int sosu(int i) {
int k;
if(i==1)
return 0;
if(i==2||i==3)
return 1;
for(k=2;k<=sqrt(i);k++)
if(i%k==0) return 0;
return 1;
}
int main() {
int a,d,n;
int i,j;
while(1){
scanf("%d %d %d",&a,&d,&n);
if(!a&&!d&&!n) break;
count=0,i=a;
while(j<n) {
if(sosu(i)) {
count++;
}
i+=d;
}
printf("%d\n",i-d);
}
return 0;
} | main.c: In function 'main':
main.c:25:9: error: 'count' undeclared (first use in this function)
25 | count=0,i=a;
| ^~~~~
main.c:25:9: note: each undeclared identifier is reported only once for each function it appears in
|
s096952857 | p00722 | C | #include <stdio.h>
int main() {
long a, d, n;
long i, j;
int pri[1000000] = {};
pri[2] = 1;
pri[3] = 1;
for(i = 5; i < 1000000; i+=2) {
for(j = 3; j < i; j++){
if(i % j == 0)
break;
if(i == j + 2)
pri[i] = 1;
}
}
while(1) {
scanf("%ld %ld %ld", &a, &d, &n);
// if(a > 9307 || d > 346 || n > 210)
// scanf("%ld %ld %ld", &a, &d, &n);
else if(a == 0 && d == 0 && n == 0)
break;
i = 0;
do{
if(pri[a] == 1)
i++;
if(i <= n)
a += d;
} while (i <= n);
printf("%ld\n", a);
}
} | main.c: In function 'main':
main.c:23:5: error: 'else' without a previous 'if'
23 | else if(a == 0 && d == 0 && n == 0)
| ^~~~
|
s974855855 | p00722 | C | #include <stdio.h>
#include <math.h>
int main(void) {
int s=1; int e=1; int d=1; int i; int m; bool result;
while(s==0 && e==0 && d==0) {
scanf("%s",s);
scanf("%s",e);
scanf("%s",d);
result=true;
m = 0;
if(s==1) {
result=false;
}
else if(s < 2) {
i=3;
while(i<sqrt(s) || result==true) {
if(s%i == 0) {
result=false;
}
i++;
}
if(result=true)
m++;
}
while(m<e) {
result=true;
s+=d;
if(s < 2) {
i=3;
while(i<sqrt(s) || result == true) {
if(s%i == 0) {
result = false;
}
i++;
}
}
if(result = true)
m++;
}
printf("%d\n", s);
}
}
| main.c: In function 'main':
main.c:5:46: error: unknown type name 'bool'
5 | int s=1; int e=1; int d=1; int i; int m; bool result;
| ^~~~
main.c:3:1: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
2 | #include <math.h>
+++ |+#include <stdbool.h>
3 |
main.c:12:16: error: 'true' undeclared (first use in this function)
12 | result=true;
| ^~~~
main.c:12:16: note: 'true' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:12:16: note: each undeclared identifier is reported only once for each function it appears in
main.c:16:20: error: 'false' undeclared (first use in this function)
16 | result=false;
| ^~~~~
main.c:16:20: note: 'false' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
|
s273343013 | p00722 | C | #include <stdio.h>
#include <math.h>
#include <stdbool.h>
int main(void) {
int s=1; int e=1; int d=1; int i; int m; result;
while(s==0 && e==0 && d==0) {
scanf("%s",s);
scanf("%s",e);
scanf("%s",d);
result=true;
m = 0;
if(s==1) {
result=false;
}
else if(s < 2) {
i=3;
while(i<sqrt(s) || result==true) {
if(s%i == 0) {
result=false;
}
i++;
}
if(result=true)
m++;
}
while(m<e) {
result=true;
s+=d;
if(s < 2) {
i=3;
while(i<sqrt(s) || result == true) {
if(s%i == 0) {
result = false;
}
i++;
}
}
if(result = true)
m++;
}
printf("%d\n", s);
}
}
| main.c: In function 'main':
main.c:6:47: error: 'result' undeclared (first use in this function)
6 | int s=1; int e=1; int d=1; int i; int m; result;
| ^~~~~~
main.c:6:47: note: each undeclared identifier is reported only once for each function it appears in
|
s015997052 | p00722 | C | //#define DEBUG
using namespace std;
bool prime[1000000] = {0};
int a, d, n;
int main(){
for(int i = 2; i < 1000; i++){
if(!prime[i]){
for(int j = i*2; j < 1000000; j+=i){
prime[j] = true;
}
}
}
prime[0] = prime [1] = 1;
#ifdef DEBUG_prime
for(int i = 2; i < 100; i++)if(!prime[i])cout<<i<<endl;
#endif
while(cin>>a>>d>>n, a||d||n){
int i, c = 0;
for(i = a; i < 1000000; i += d){
if(!prime[i]){
c++;
if(c == n)break;
}
}
cout<<i<<endl;
}
return 0;
} | main.c:2:1: error: unknown type name 'using'
2 | using namespace std;
| ^~~~~
main.c:2:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'std'
2 | using namespace std;
| ^~~
main.c:4:1: error: unknown type name 'bool'
4 | bool prime[1000000] = {0};
| ^~~~
main.c:1:1: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
+++ |+#include <stdbool.h>
1 | //#define DEBUG
main.c: In function 'main':
main.c:11:44: error: 'true' undeclared (first use in this function)
11 | prime[j] = true;
| ^~~~
main.c:11:44: note: 'true' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:11:44: note: each undeclared identifier is reported only once for each function it appears in
main.c:19:15: error: 'cin' undeclared (first use in this function)
19 | while(cin>>a>>d>>n, a||d||n){
| ^~~
main.c:27:17: error: 'cout' undeclared (first use in this function)
27 | cout<<i<<endl;
| ^~~~
main.c:27:26: error: 'endl' undeclared (first use in this function)
27 | cout<<i<<endl;
| ^~~~
|
s589430458 | p00722 | C | C[1000000];
main(){
int i,j,a,d,n;
C[1]=1;
for(i=2;i<500000;i++)
for(j=i*2;j<1000000;j+=i)
C[j]=1;
for(;scanf("%d%d%d",&a,&d,&n),n;){
a-=d;
for(;n--;){
for(;C[a+=d];);
}
printf("%d\n",a);
}
exit(!puts("")); | main.c:1:1: warning: data definition has no type or storage class
1 | C[1000000];
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 'C' [-Wimplicit-int]
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
2 | main(){
| ^~~~
main.c: In function 'main':
main.c:8:14: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
8 | for(;scanf("%d%d%d",&a,&d,&n),n;){
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | C[1000000];
main.c:8:14: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
8 | for(;scanf("%d%d%d",&a,&d,&n),n;){
| ^~~~~
main.c:8:14: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:13:17: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
13 | printf("%d\n",a);
| ^~~~~~
main.c:13:17: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:13:17: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:13:17: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:15:9: error: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
15 | exit(!puts(""));
| ^~~~
main.c:1:1: note: include '<stdlib.h>' or provide a declaration of 'exit'
+++ |+#include <stdlib.h>
1 | C[1000000];
main.c:15:9: warning: incompatible implicit declaration of built-in function 'exit' [-Wbuiltin-declaration-mismatch]
15 | exit(!puts(""));
| ^~~~
main.c:15:9: note: include '<stdlib.h>' or provide a declaration of 'exit'
main.c:15:15: error: implicit declaration of function 'puts' [-Wimplicit-function-declaration]
15 | exit(!puts(""));
| ^~~~
main.c:15:15: note: include '<stdio.h>' or provide a declaration of 'puts'
main.c:15:9: error: expected declaration or statement at end of input
15 | exit(!puts(""));
| ^~~~
|
s673290000 | p00722 | C++ | #include <iostream>
#include<string>
#include<cmath>
#include<stack>
#include<map>
int main()
{
while(1){
int a,d,n;
cin>>a>>d>>n;
if(a==0 and d==0 and n==0){break;}
num=d*n;
anseru=a+num;
cout<<anseru;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:12:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
12 | cin>>a>>d>>n;
| ^~~
| std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
62 | extern istream cin; ///< Linked to standard input
| ^~~
a.cc:15:5: error: 'num' was not declared in this scope; did you mean 'enum'?
15 | num=d*n;
| ^~~
| enum
a.cc:17:5: error: 'anseru' was not declared in this scope
17 | anseru=a+num;
| ^~~~~~
a.cc:20:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
20 | cout<<anseru;
| ^~~~
| std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
63 | extern ostream cout; ///< Linked to standard output
| ^~~~
|
s650281762 | p00722 | C++ | #include <iostream>
#include<string>
#include<cmath>
#include<stack>
#include<map>
using namespace std;
#define NUM 1000001
int main()
{
//素数チェックに用いるーーーーーーーーー
int* table = new int[NUM];
int limit;
for(int i=0; i < NUM;i++)table[i] = 1;
table[0]=0;
table[1]=0;
limit = sqrt(NUM);
cout<<"limit"<<limit<<endl;
for(int i=2;i<=limit;i++){
if(table[i] == 1){
for(int k=2*i;k < NUM; k += i){
table[k] = 0;
}
}
}
//ーーーーーーーーーーーーーーーーーーーーーーーーーーーー
int a,d,n;
int anser;
while(1){
cin>>a>>d>>n;
anser=0;
if(a==0 and d==0 and n==0){break;}
for(int i=1; i<= 1000000; i++){
if(table[a+(i-1)*d] == 1)count++;
if(count == n){
cout<<a+(i-1)*d<<endl;
break;
}
}
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:47:38: error: 'count' was not declared in this scope
47 | if(table[a+(i-1)*d] == 1)count++;
| ^~~~~
a.cc:48:16: error: 'count' was not declared in this scope
48 | if(count == n){
| ^~~~~
|
s654227053 | p00722 | C++ | #include <iostream>
#include <cmath>
#include <vector>
using namespace std;
bool isPrime(int a)
{
bool result = true;
for (int i = 2; i < sqrt(a); i += (i == 2 ? 1 : 2)) {
if (i>3 && i % 3 == 0) continue;
if (a%i == 0) {
result = !result;
break;
}
}
return result;
}
int main()
{
vector<int> prime;
prime.push_back(2);
for (int i = 3; i < 1000000; i += 2) {
if (isPrime(i)) {
prime.push_back(i);
}
}
int a, d, n;
for (cin >> a >> d >> n; a || d || n; cin >> a >> d >> n) {
vector<int>::iterator prev = find(prime.begin(), prime.end(), a);
if (prev == prime.end()) {
prev = prime.begin();
}
for (int i = 0; i < n; a += d) {
vector<int>::iterator answer = find(prev, prime.end(), a);
if (answer != prime.end()) {
prev = answer;
i++;
}
}
cout << a - d << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:31:50: error: no matching function for call to 'find(std::vector<int>::iterator, std::vector<int>::iterator, int&)'
31 | vector<int>::iterator prev = find(prime.begin(), prime.end(), a);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/locale_facets.h:48,
from /usr/include/c++/14/bits/basic_ios.h:37,
from /usr/include/c++/14/ios:46,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
435 | find(istreambuf_iterator<_CharT> __first,
| ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: template argument deduction/substitution failed:
a.cc:31:50: note: '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
31 | vector<int>::iterator prev = find(prime.begin(), prime.end(), a);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:36:60: error: no matching function for call to 'find(std::vector<int>::iterator&, std::vector<int>::iterator, int&)'
36 | vector<int>::iterator answer = find(prev, prime.end(), a);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)'
435 | find(istreambuf_iterator<_CharT> __first,
| ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: template argument deduction/substitution failed:
a.cc:36:60: note: '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' is not derived from 'std::istreambuf_iterator<_CharT>'
36 | vector<int>::iterator answer = find(prev, prime.end(), a);
| ~~~~^~~~~~~~~~~~~~~~~~~~~~
|
s057335122 | p00722 | C++ | #include <iostream>
using namespace std;
typedef long long ll;
bool isPrime(int n) {
if (i <= 1) return false;
for (int i = 2; i*i <= n; ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main() {
int a, d, n;
while ( cin >> a >> d >> n, a || d || n ) {
int cnt = 0;
int ans = 0;
for (ll i = a;; i += d) {
if (isPrime(i)) {
if (++cnt == n) {
ans = i;
break;
}
}
}
cout << ans << endl;
}
} | a.cc: In function 'bool isPrime(int)':
a.cc:8:13: error: 'i' was not declared in this scope
8 | if (i <= 1) return false;
| ^
|
s130440590 | p00722 | C++ |
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
using namespace std;
//与えられた数が素数かどうか判定する
int isPrime(unsigned long long int x) {
if(x == 0) return 0;
if(x == 1) return 0;
int flg = 1;
for(int i = 2; i < (int)sqrt((double)x) + 1; i++) {
if(x % i == 0) {
flg = 0;
break;
}
}
return flg;
}
int main(void){
//FILE* fp_in = freopen("data.txt", "r", stdin);
while(1) {
unsigned long long int a, d, n;
unsigned long long int ans, tmp;
int cnt = 0;
cin >> a >> d >> n;
tmp = a;
if( a == 0 && d == 0 && n == 0 ) break; //終了処理
//素数を求めるループ
while(1) {
if( isPrime(tmp) ) cnt ++;
if( cnt == n ) {
ans = tmp;
break;
}
tmp += d;
}
//出力
cout << ans << endl;
}
//while(1){}
return 0;
} | a.cc: In function 'int isPrime(long long unsigned int)':
a.cc:17:33: error: 'sqrt' was not declared in this scope
17 | for(int i = 2; i < (int)sqrt((double)x) + 1; i++) {
| ^~~~
|
s539329689 | p00722 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()
const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;
/*テァツエツ?ヲツ閉ーテ・ツ按、テ・ツョツ?/
const int MAX = 1000100;
bool prime[MAX];
void sieve(){
fill(prime, prime+MAX, true);
prime[0] = prime[1] = false;
for(int i=0; i < MAX; i++){
if(!prime[i]) continue;
for(int j=i+i; j < MAX; j += i){
prime[j] = false;
}
}
}
int main(){
int a, d, n;
sieve();
while(cin >> a >> d >> n, a+d+n){
int count = 0;
while(true){
if(prime[a]) n--;
if(n == 0) break;
a+=d;
}
cout << a << endl;
}
} | a.cc:14:1: error: unterminated comment
14 | /*テァツエツ?ヲツ閉ーテ・ツ按、テ・ツョツ?/
| ^
|
s667835782 | p00722 | C++ | 92809
6709
12037
103
93523
14503
2
899429
5107
412717
22699
25673 | a.cc:1:1: error: expected unqualified-id before numeric constant
1 | 92809
| ^~~~~
|
s840999426 | p00722 | C++ | #include <stdio.h>
int a, d, n;
int m, x;
int temp;
int main(void)
{
while(1) {
scanf("%d %d %d", &a, &d, &n);
if (a == 0) break;
m = a;
while(n > 0) {
temp = 0;
if (m > 1) {
for (x = 2; x <= m / 2 + 1; x++) {
if (m % x == 0) {
temp = 1;
break;
}
}
if (temp == 0) {
n--;
}
m += d;
}
printf("%d\n", m - d);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:31:2: error: expected '}' at end of input
31 | }
| ^
a.cc:8:1: note: to match this '{'
8 | {
| ^
|
s190552412 | p00722 | C++ | #include <stdio.h>
int a, d, n;
int m, x;
int temp;
int main(void)
{
while(1) {
scanf("%d %d %d", &a, &d, &n);
if (a == 0) break;
m = a;
while(1) {
temp = 0;
if (m > 1) {
for (x = 2; x <= m / 2 + 1; x++) {
if (m % x == 0) {
temp = 1;
break;
}
}
if (temp == 0) {
n--;
}
if (n = 0) break;
m += d;
}
printf("%d\n", m);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:32:2: error: expected '}' at end of input
32 | }
| ^
a.cc:8:1: note: to match this '{'
8 | {
| ^
|
s207057375 | p00722 | C++ | #include<iostream>
using namespace std;
int main(){
int a,d,n,so[1000000]={},i,j;
so[1]=1;
for(i=2;i<1000;i++)if(so[i]==0)for(j=2;i*j<1000000;j++)so[i*j]=1;
while(1){
cin>>a>>d>>n;
if(n==0)break;
j=0;
for(i=a;c<n;i+=d)if(so[i]==0)j++;
cout<<i-d<<endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:11:13: error: 'c' was not declared in this scope
11 | for(i=a;c<n;i+=d)if(so[i]==0)j++;
| ^
|
s325068255 | p00722 | C++ | #include <iostream>
bool isprime(int n,int k=2){if(n==1){return false;}if(n<k*k){return true;}if(n%k==0){return false;}return isprime(n,k+1);}int main(){int a,d,n,c;while(true){std::cin>>a>>d>>n;if(n==0){break;}c=0;while(c<n){if(isprime(a)){c++;}a+=d;}std::cout<<a-d<<endl;}} | a.cc: In function 'int main()':
a.cc:2:249: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
2 | bool isprime(int n,int k=2){if(n==1){return false;}if(n<k*k){return true;}if(n%k==0){return false;}return isprime(n,k+1);}int main(){int a,d,n,c;while(true){std::cin>>a>>d>>n;if(n==0){break;}c=0;while(c<n){if(isprime(a)){c++;}a+=d;}std::cout<<a-d<<endl;}}
| ^~~~
| std::endl
In file included from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
744 | endl(basic_ostream<_CharT, _Traits>& __os)
| ^~~~
|
s759298941 | p00722 | C++ | #include<iostream>
using namespace std; int a, b, c, i, n;
int main() {
while (true) {
n = 0;
cin >> a >> b >> c;
if (!a) {
break;
}
while(n<c){
for (i = 2; i <= sqrt(a); i++) {
if (a%i == 0) {
goto E;
}
}
n++;
E:;
a += b;
}
cout << a - b << endl;
}
} | a.cc: In function 'int main()':
a.cc:11:42: error: 'sqrt' was not declared in this scope
11 | for (i = 2; i <= sqrt(a); i++) {
| ^~~~
|
s972941287 | p00722 | C++ | #include<iostream>
using namespace std; int a, b, c, i, n;
int main() {
while (true) {
n = 0;
cin >> a >> b >> c;
if (!a) {
break;
}
while(n<c){
if (a < 2) {
goto E;
}
for (i = 2; i <= sqrt(a); i++) {
if (a%i == 0) {
goto E;
}
}
n++;
E:;
a += b;
}
cout << a - b << endl;
}
} | a.cc: In function 'int main()':
a.cc:14:42: error: 'sqrt' was not declared in this scope
14 | for (i = 2; i <= sqrt(a); i++) {
| ^~~~
|
s240744122 | p00722 | C++ | #include<iostream>
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=(j);i<=(k);i++)
#define fs first
#define sc second
#define pb push_back
using namespace std;
#define N 1000000
int inp[N];
int main(){
int a,d,n;
inp[0]=inp[1]=1;
reps(i,2,N-1){
if(!inp[i])for(int j=i*2;j<N;j+=i)inp[j]=1;
}
while(cin >> a >> d >> n){
if(!(a+d+n))break;
while(n){
if(!inp[a]) n--;
a += d;
}
cin << a-d << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:25:5: error: no match for 'operator<<' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'int')
25 | cin << a-d << endl;
| ~~~ ^~ ~~~
| | |
| | int
| std::istream {aka std::basic_istream<char>}
a.cc:25:5: note: candidate: 'operator<<(int, int)' (built-in)
25 | cin << a-d << endl;
| ~~~~^~~~~~
a.cc:25:5: note: no known conversion for argument 1 from 'std::istream' {aka 'std::basic_istream<char>'} to 'int'
In file included from /usr/include/c++/14/bits/basic_string.h:47,
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:1:
/usr/include/c++/14/string_view:763:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, basic_string_view<_CharT, _Traits>)'
763 | operator<<(basic_ostream<_CharT, _Traits>& __os,
| ^~~~~~~~
/usr/include/c++/14/string_view:763:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/bits/basic_string.h:4077:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
4077 | operator<<(basic_ostream<_CharT, _Traits>& __os,
| ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4077:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
25 | cin << a-d << endl;
| ^
In file included from /usr/include/c++/14/bits/memory_resource.h:38,
from /usr/include/c++/14/string:68:
/usr/include/c++/14/cstddef:125:5: note: candidate: 'template<class _IntegerType> constexpr std::__byte_op_t<_IntegerType> std::operator<<(byte, _IntegerType)'
125 | operator<<(byte __b, _IntegerType __shift) noexcept
| ^~~~~~~~
/usr/include/c++/14/cstddef:125:5: note: template argument deduction/substitution failed:
a.cc:25:1: note: cannot convert 'std::cin' (type 'std::istream' {aka 'std::basic_istream<char>'}) to type 'std::byte'
25 | cin << a-d << endl;
| ^~~
In file included from /usr/include/c++/14/bits/ios_base.h:46:
/usr/include/c++/14/system_error:339:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const error_code&)'
339 | operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __e)
| ^~~~~~~~
/usr/include/c++/14/system_error:339:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:563:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, _CharT)'
563 | operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:563:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:573:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, char)'
573 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:573:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:579:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, char)'
579 | operator<<(basic_ostream<char, _Traits>& __out, char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:579:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:590:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, signed char)'
590 | operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:590:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:595:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, unsigned char)'
595 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
| ^~~~~~~~
/usr/include/c++/14/ostream:595:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:654:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const _CharT*)'
654 | operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
| ^~~~~~~~
/usr/include/c++/14/ostream:654:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
25 | cin << a-d << endl;
| ^
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:307:5: note: candidate: 'template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(basic_ostream<_CharT, _Traits>&, const char*)'
307 | operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
| ^~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:307:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<_CharT, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:671:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, const char*)'
671 | operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
| ^~~~~~~~
/usr/include/c++/14/ostream:671:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:684:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, const signed char*)'
684 | operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
| ^~~~~~~~
/usr/include/c++/14/ostream:684:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:689:5: note: candidate: 'template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(basic_ostream<char, _Traits>&, const unsigned char*)'
689 | operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
| ^~~~~~~~
/usr/include/c++/14/ostream:689:5: note: template argument deduction/substitution failed:
a.cc:25:10: note: 'std::istream' {aka 'std::basic_istream<char>'} is not derived from 'std::basic_ostream<char, _Traits>'
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:810:5: note: candidate: 'template<class _Ostream, class _Tp> _Ostream&& std::operator<<(_Ostream&&, const _Tp&)'
810 | operator<<(_Ostream&& __os, const _Tp& __x)
| ^~~~~~~~
/usr/include/c++/14/ostream:810:5: note: template argument deduction/substitution failed:
/usr/include/c++/14/ostream: In substitution of 'template<class _Ostream, class _Tp> _Ostream&& std::operator<<(_Ostream&&, const _Tp&) [with _Ostream = std::basic_istream<char>&; _Tp = int]':
a.cc:25:10: required from here
25 | cin << a-d << endl;
| ^
/usr/include/c++/14/ostream:810:5: error: no type named 'type' in 'struct std::enable_if<false, void>'
810 | operator<<(_Ostream&& __os, const _Tp& __x)
| ^~~~~~~~
|
s105939450 | p00722 | C++ | 367 186 151
179 10 203
271 37 39
103 230 1
27 104 185
253 50 85
1 1 1
9075 337 210
307 24 79
331 221 177
259 170 40
269 58 102
0 0 0 | a.cc:1:1: error: expected unqualified-id before numeric constant
1 | 367 186 151
| ^~~
|
s596059789 | p00722 | C++ | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int Prime(int p){
int i,f;
f = 0;
if(p == 1) return 0;
if(p == 2) return 1;
if(p % 2 == 0) return 0;
for(i=3;i*i <= p;i += 2){
if(p % i == 0) f = 1;
}
if(f == 0) return 1;
else return 0;
}
int main() {
int a,d,n;
int i,count;
while(1) {
scanf("%d %d %d",&a,&d,&n);
if(!a&&!d&&!n) break;
count=0,i=a;
while(count<n) {
if(prime(i)) {
count++;
}
i+=d;
//printf("%d\n",i);
}
printf("%d\n",i-d);
}
return 0;
} | a.cc: In function 'int main()':
a.cc:28:16: error: 'prime' was not declared in this scope; did you mean 'Prime'?
28 | if(prime(i)) {
| ^~~~~
| Prime
|
s683383122 | p00722 | C++ | #include <bits/stdc++.h>
#define INF INT_MAX
#define ll long long
#define MAX_SIZE 1100000 //??????????????§???+10???
using namespace std;
bool is_prime[MAX_SIZE]; //true:?´???°???false:?´???°??\???
//n??\???????´???°?????°????±???????
int sieve(int n){
for(int i = 0;i <= n;i++)is_prime[i] = true;
is_prime[0] = is_prime[1] = false; //0??¨1????´???°??§?????????
for(int i = 2;i <= n;i++){
if(is_prime[i]){
//n??\??????n?????°?????????false?????????
for(int j = 2*i; j <= n;j+=i){
is_prime[j] = false;
}
}
}
}
//?????????a,?????????d???????????°??????n????????????????´???°????????????
getNPrimeForProgression(int a,int d,int n){
int c = 0,i = 1;
while(c < n){
if(is_prime[a+d*(i++-1)])c++;
}
i--;
return a+d*(i-1);
}
int main(){
int a,d,n;
sieve(MAX_SIZE); //MAX_SIZE?????§????´???°????±???????
while(scanf("%d %d %d",&a,&d,&n) != EOF){
if(a == 0 || d == 0 || n == 0)break;
cout << getNPrimeForProgression(a,d,n) << endl;
}
return 0;
} | a.cc: In function 'int sieve(int)':
a.cc:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
24 | }
| ^
a.cc: At global scope:
a.cc:27:1: error: ISO C++ forbids declaration of 'getNPrimeForProgression' with no type [-fpermissive]
27 | getNPrimeForProgression(int a,int d,int n){
| ^~~~~~~~~~~~~~~~~~~~~~~
|
s985228612 | p00722 | C++ | #include <bits/stdc++.h>
#define INF INT_MAX
#define ll long long
#define MAX_SIZE 1100000 //??????????????§???+10???
using namespace std;
bool is_prime[MAX_SIZE]; //true:?´???°???false:?´???°??\???
//n??\???????´???°?????°????±???????
int sieve(int n){
for(int i = 0;i <= n;i++)is_prime[i] = true;
is_prime[0] = is_prime[1] = false; //0??¨1????´???°??§?????????
for(int i = 2;i <= n;i++){
if(is_prime[i]){
//n??\??????n?????°?????????false?????????
for(int j = 2*i; j <= n;j+=i){
is_prime[j] = false;
}
}
}
}
//?????????a,?????????d???????????°??????n????????????????´???°????????????
void getNPrimeForProgression(int a,int d,int n){
int c = 0,i = 1;
while(c < n){
if(is_prime[a+d*(i++-1)])c++;
}
i--;
return a+d*(i-1);
}
int main(){
int a,d,n;
sieve(MAX_SIZE); //MAX_SIZE?????§????´???°????±???????
while(scanf("%d %d %d",&a,&d,&n) != EOF){
if(a == 0 || d == 0 || n == 0)break;
cout << getNPrimeForProgression(a,d,n) << endl;
}
return 0;
} | a.cc: In function 'int sieve(int)':
a.cc:24:1: warning: no return statement in function returning non-void [-Wreturn-type]
24 | }
| ^
a.cc: In function 'void getNPrimeForProgression(int, int, int)':
a.cc:33:17: error: return-statement with a value, in function returning 'void' [-fpermissive]
33 | return a+d*(i-1);
| ~^~~~~~~~
a.cc: In function 'int main()':
a.cc:41:22: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'void')
41 | cout << getNPrimeForProgression(a,d,n) << endl;
| ~~~~ ^~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | |
| | void
| std::ostream {aka std::basic_ostream<char>}
In file included from /usr/include/c++/14/istream:41,
from /usr/include/c++/14/sstream:40,
from /usr/include/c++/14/complex:45,
from /usr/include/c++/14/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
from a.cc:1:
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
116 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note: no known conversion for argument 1 from 'void' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
116 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
125 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note: no known conversion for argument 1 from 'void' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
125 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
135 | operator<<(ios_base& (*__pf) (ios_base&))
| ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note: no known conversion for argument 1 from 'void' to 'std::ios_base& (*)(std::ios_base&)'
135 | operator<<(ios_base& (*__pf) (ios_base&))
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
174 | operator<<(long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:174:23: note: no known conversion for argument 1 from 'void' to 'long int'
174 | operator<<(long __n)
| ~~~~~^~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
178 | operator<<(unsigned long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:178:32: note: no known conversion for argument 1 from 'void' to 'long unsigned int'
178 | operator<<(unsigned long __n)
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
182 | operator<<(bool __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:182:23: note: no known conversion for argument 1 from 'void' to 'bool'
182 | operator<<(bool __n)
| ~~~~~^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
96 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:97:22: note: no known conversion for argument 1 from 'void' to 'short int'
97 | operator<<(short __n)
| ~~~~~~^~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
189 | operator<<(unsigned short __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:189:33: note: no known conversion for argument 1 from 'void' to 'short unsigned int'
189 | operator<<(unsigned short __n)
| ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
110 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:111:20: note: no known conversion for argument 1 from 'void' to 'int'
111 | operator<<(int __n)
| ~~~~^~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
200 | operator<<(unsigned int __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:200:31: note: no known conversion for argument 1 from 'void' to 'unsigned int'
200 | operator<<(unsigned int __n)
| ~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
211 | operator<<(long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:211:28: note: no known conversion for argument 1 from 'void' to 'long long int'
211 | operator<<(long long __n)
| ~~~~~~~~~~^~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
215 | operator<<(unsigned long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:215:37: note: no known conversion for argument 1 from 'void' to 'long long unsigned int'
215 | operator<<(unsigned long long __n)
| ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
231 | operator<<(double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:231:25: note: no known conversion for argument 1 from 'void' to 'double'
231 | operator<<(double __f)
| ~~~~~~~^~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
235 | operator<<(float __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:235:24: note: no known conversion for argument 1 from 'void' to 'float'
235 | operator<<(float __f)
| ~~~~~~^~~
/usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
243 | operator<<(long double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:243:30: note: no known conversion for argument 1 from 'void' to 'long double'
243 | operator<<(long double __f)
| ~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:301:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
301 | operator<<(const void* __p)
| ^~~~~~~~
/usr/include/c++/14/ostream:301:30: note: no known conversion for argument 1 from 'void' to 'const void*'
301 | operator<<(const void* __p)
| ~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:306:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::nullptr_t) [with _CharT = char; _Traits = std::char_traits<char>; __o |
s009607638 | p00722 | C++ | #include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<set>
#include<functional>
using namespace std;
#define INF 1<<21
#define MOD 1000000007
#define MAX 1000000
int main() {
int p[MAX];
memset(p, 1, sizeof(p));
p[0] = 0;
p[1] = 0;
for (int i = 2; i <= sqrt(MAX)+1; i++) {
if (p[i] == 1) {
for (int j = 2*i; j <= MAX; j += i) {
p[j] = 0;
}
}
}
int a, d, n;
while (1) {
cin >> a >> d >> n;
if (a == 0 && d == 0 && n == 0)return 0;
while (1) {
if (p[a] == 1) n--;
if (n == 0) {
cout << a << endl;
break;
}
a += d;
}
}
} | a.cc: In function 'int main()':
a.cc:20:24: error: 'sqrt' was not declared in this scope
20 | for (int i = 2; i <= sqrt(MAX)+1; i++) {
| ^~~~
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.