Submission #36785

#TimeUsernameProblemLanguageResultExecution timeMemory
36785kjain_1810Retro (COCI17_retro)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #define ind(a) scanf("%d", &a) #define inlld(a) scanf("%lld", &a) #define pb push_back #define f first #define s second using namespace std; const int N=1e5+5; typedef long long ll; int r, s; int dp[305][305][305]; pair<int,int> backtrack[305][305]; char str[305][305][305]; int solve(int i, int j, int numopen) { if(i==0 && numopen==0) return 0; else if(i==0) return -1e9; if(numopen<0) return -1e9; if(str[i][j]=='*' && numopen==0) return 0; else if(str[i][j]=='*') return -1e9; if(dp[i][j][numopen]!=-1) return dp[i][j][numopen]; if(str[i][j]=='M' || str[i][j]=='.') { int ans=solve(i-1, j, numopen); backtrack[i][j]={0,0}; if(j>1) { int tmp=solve(i-1, j-1, numopen); if(tmp>ans) { ans=tmp; backtrack[i][j]={-1, 0}; } } if(j<s) { int tmp=solve(i-1, j+1, numopen); if(tmp>ans) { ans=tmp; backtrack[i][j]={1, 0}; } } return dp[i][j][numopen]=ans; } if(str[i][j]=='(') { int ans=solve(i-1, j, numopen+1); backtrack[i][j]={0, 1}; if(j>1) { int tmp=solve(i-1, j-1, numopen+1); if(tmp>ans) { ans=tmp; backtrack[i][j]={-1, 1}; } } if(j<s) { int tmp=solve(i-1, j+1, numopen+1); if(tmp>ans) { ans=tmp; backtrack[i][j]={1, 1}; } } return dp[i][j][numopen]=ans; } else if(str[i][j]==')') { int ans=solve(i-1, j, numopen-1)+1; backtrack[i][j]=0; if(j>1) { int tmp=solve(i-1, j-1, numopen-1)+1; if(tmp>ans) { ans=tmp; backtrack[i][j]={-1, -1}; } // ans=max(ans, solve(i-1, j-1, numopen-1)+1); } if(j<s) { int tmp=solve(i-1, j+1, numopen-1)+1; if(tmp>ans) { ans=tmp; backtrack[i][j]={1, -1}; } // ans=max(ans, solve(i-1, j+1, numopen-1)+1); } return dp[i][j][numopen]=ans; } } int main() { ind(r); ind(s); for(int a=1; a<=r; a++) for(int b=1; b<=s; b++) cin>>str[a][b]; memset(dp, -1, sizeof(dp)); int starti, startj; for(int a=1; a<=s; a++) if(str[r][a]=='M') { starti=r; startj=a; break; } printf("%d\n", 2*solve(starti, startj, 0)); int i=r, j=startj, num=0; while(1) { if(str[i][j]=='*' || i==0 || num<0) break; if(str[i][j]=='(' || str[i][j]==')') printf("%c", str[i][j]); j+=backtrack[i][j].f; num+=backtrack[i][j].s; i--; } printf("\n"); return 0; }

Compilation message (stderr)

retro.cpp: In function 'int solve(int, int, int)':
retro.cpp:22:16: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  if(str[i][j]=='*' && numopen==0)
                ^
retro.cpp:24:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  else if(str[i][j]=='*')
                     ^
retro.cpp:28:16: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  if(str[i][j]=='M' || str[i][j]=='.')
                ^
retro.cpp:28:34: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  if(str[i][j]=='M' || str[i][j]=='.')
                                  ^
retro.cpp:52:16: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  if(str[i][j]=='(')
                ^
retro.cpp:76:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  else if(str[i][j]==')')
                     ^
retro.cpp:79:18: error: no match for 'operator=' (operand types are 'std::pair<int, int>' and 'int')
   backtrack[i][j]=0;
                  ^
In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/istream:38,
                 from /usr/include/c++/5/sstream:38,
                 from /usr/include/c++/5/complex:45,
                 from /usr/include/c++/5/ccomplex:38,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52,
                 from retro.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:158:7: note: candidate: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_T1, _T2>&) [with _T1 = int; _T2 = int]
       operator=(const pair& __p)
       ^
/usr/include/c++/5/bits/stl_pair.h:158:7: note:   no known conversion for argument 1 from 'int' to 'const std::pair<int, int>&'
/usr/include/c++/5/bits/stl_pair.h:166:7: note: candidate: std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_T1, _T2>&&) [with _T1 = int; _T2 = int]
       operator=(pair&& __p)
       ^
/usr/include/c++/5/bits/stl_pair.h:166:7: note:   no known conversion for argument 1 from 'int' to 'std::pair<int, int>&&'
/usr/include/c++/5/bits/stl_pair.h:177:2: note: candidate: template<class _U1, class _U2> std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]
  operator=(const pair<_U1, _U2>& __p)
  ^
/usr/include/c++/5/bits/stl_pair.h:177:2: note:   template argument deduction/substitution failed:
retro.cpp:79:18: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   backtrack[i][j]=0;
                  ^
In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/5/bits/char_traits.h:39,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/istream:38,
                 from /usr/include/c++/5/sstream:38,
                 from /usr/include/c++/5/complex:45,
                 from /usr/include/c++/5/ccomplex:38,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52,
                 from retro.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:186:2: note: candidate: template<class _U1, class _U2> std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U1 = _U1; _U2 = _U2; _T1 = int; _T2 = int]
  operator=(pair<_U1, _U2>&& __p)
  ^
/usr/include/c++/5/bits/stl_pair.h:186:2: note:   template argument deduction/substitution failed:
retro.cpp:79:18: note:   mismatched types 'std::pair<_T1, _T2>' and 'int'
   backtrack[i][j]=0;
                  ^
retro.cpp: In function 'int main()':
retro.cpp:113:17: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if(str[r][a]=='M')
                 ^
retro.cpp:123:17: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if(str[i][j]=='*' || i==0 || num<0)
                 ^
retro.cpp:125:17: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if(str[i][j]=='(' || str[i][j]==')')
                 ^
retro.cpp:125:35: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   if(str[i][j]=='(' || str[i][j]==')')
                                   ^
retro.cpp:126:26: warning: format '%c' expects argument of type 'int', but argument 2 has type 'char*' [-Wformat=]
    printf("%c", str[i][j]);
                          ^
retro.cpp: In function 'int solve(int, int, int)':
retro.cpp:102:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
retro.cpp: In function 'int main()':
retro.cpp:105:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  ind(r);
        ^
retro.cpp:106:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  ind(s);
        ^