fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. string N[105];
  4. int cnt,t;
  5. int gcd(int y){
  6. string s;
  7. getline(cin,s);
  8. if(s[0]=='F'){
  9. string nn,S,E,check;
  10. S=s[2],E=s[3],nn=s[1];
  11. for(int i=1;i<=cnt;i++){
  12. if(N[i]==nn){
  13. cout<<"ERR\n";
  14. return -1;
  15. }
  16. }
  17. N[++cnt]=nn;
  18. gcd(y+1);
  19. getline(cin,check);
  20. if(check[0]=='E'){
  21. if(E[0]<'9' && E[0]>'0'){
  22. return 0;
  23. }else{
  24. if(S[0]=='n'){
  25. return 0;
  26. }else{
  27. return 1+y;
  28. }
  29. }
  30. }else{
  31. cout<<"ERR\n";
  32. return -1;
  33. }
  34.  
  35. }else{
  36. cout<<"ERR\n";
  37. return -1;
  38. }
  39. }
  40. int main() {
  41. ios::sync_with_stdio(false);
  42. cin.tie(0),cout.tie(0);
  43. cin>>t;
  44. for(int i=1;i<=t;i++){
  45. int to=0,cnt=0;
  46. int n;
  47. cin>>n;
  48. string l;
  49. cin>>l;
  50. int r=gcd(0);
  51. if(r==-1){
  52. continue;
  53. }
  54. bool flag=false;
  55. for(int i=0;i<=l.size();i++){
  56. if(l[i+1]==')'){
  57. to=l[i+1]-'0'+to*10;
  58. break;
  59. }else if(l[i]>='0' && l[i]<='9'){
  60. to=l[i+1]-'0'+to*10;
  61. }
  62. if(l[i]=='^'){
  63. flag=true;
  64. }
  65. }
  66. if(flag==false){
  67. if(r==0){
  68. cout<<"Yes\n";
  69. }else{
  70. cout<<"No\n";
  71. }
  72. }else{
  73. if(r==to){
  74. cout<<"Yes\n";
  75. }else{
  76. cout<<"No\n";
  77. }
  78. }
  79. }
  80. return 0;
  81. }
Success #stdin #stdout 0.01s 5288KB
stdin
8
2 O(1)
F i 1 1
E
2 O(n^1)
F x 1 n
E
1 O(1)
F x 1 n
4 O(n^2)
F x 5 n
F y 10 n
E
E
4 O(n^2)
F x 9 n
E
F y 2 n
E
4 O(n^1)
F x 9 n
F y n 4
E
E
4 O(1)
F y n 4
F x 9 n
E
E
4 O(n^2)
F x 1 n
F x 1 10
E
E
stdout
ERR
ERR
ERR
ERR
ERR
ERR
ERR
ERR