fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //ifstream fin ("C:\\Users\\Anushi Maheshwari\\Documents\\CodeChef\\Test\\Test.out");
  5. //ofstream fout ("C:\\Users\\Anushi Maheshwari\\Documents\\CodeChef\\Checker\\Wrong.txt");
  6.  
  7. #define FileIn() freopen("C:\\Users\\Anushi Maheshwari\\Documents\\CodeChef\\Test\\Test.out", "r", stdin)
  8. #define FileOut() freopen("C:\\Users\\Anushi Maheshwari\\Documents\\CodeChef\\Checker\\Wrong.txt", "w", stdout)
  9.  
  10. #define N 1000010
  11. #define mod 1000000007
  12. #define f first
  13. #define s second
  14.  
  15. char a[5][5];
  16. char s[20];
  17. int res;
  18. bool vis[5][5];
  19. int dx[]={1,1,-1,-1,0,0,1,-1};
  20. int dy[]={1,0,-1,0,1,-1,-1,1};
  21.  
  22. int score(int x){
  23. return (x<5)?1:(x>7)?11:x-3;
  24. }
  25.  
  26. bool dfs(int x,int y,unsigned int id){
  27. if(id==strlen(s)) return 1;
  28. if(x<0 || x>3 || y<0 || y>3 || vis[x][y] || a[x][y]!=s[id]) return 0;
  29. vis[x][y]=1;
  30. bool ans=0;
  31. for(int i=0;i<8 && (!ans);i++)
  32. ans|=dfs(x+dx[i],y+dy[i],id+1);
  33. vis[x][y]=0;
  34. return ans;
  35. }
  36.  
  37. void solve(){
  38. bool ok=0;
  39. for(int i=0;i<5 && (!ok);i++)
  40. for(int j=0;j<5 && (!ok);j++){
  41. ok|=dfs(i,j,0);
  42. }
  43. if(ok) res+=score(strlen(s));
  44. }
  45.  
  46.  
  47. int main(){
  48. //FileIn();FileOut();
  49. int t,q;
  50. scanf("%d",&t);
  51. for(int test=1;test<=t;test++){
  52. for(int i=0;i<4;i++)
  53. scanf("%s",a[i]);
  54. scanf("%d",&q);
  55. res=0;
  56. while(q--){
  57. scanf("%s",s);
  58. solve();
  59. }
  60. printf("Score for Boggle game #%d: %d\n",test,res);
  61. //printf("%d\n",res);
  62. }
  63. return 0;
  64. }
  65.  
Runtime error #stdin #stdout #stderr 0.01s 27704KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
  File "./prog.py", line 2
    using namespace std;
                  ^
SyntaxError: invalid syntax