Patrickmeme

Soricel- nerdarena

Dec 26th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include <fstream>
  2. #include <math.h>
  3. using namespace std;
  4. ifstream cin("soricel.in");
  5. ofstream cout("soricel.out");
  6. int v[200][200];
  7.  
  8. int main()
  9. {
  10.     int cer,n,m,k,lin,col,max1,cnt,a,la,s,e,mis,ci;
  11.     cin>>cer>>n>>m>>k;
  12.     max1=1;
  13.     cnt=0;
  14.     for(lin=0;lin<n;lin++){
  15.         for(col=0;col<m;col++){
  16.             cin>>v[lin][col];
  17.             if(v[lin][col]>1){
  18.                 a=sqrt(v[lin][col]-1);
  19.                 v[lin][col]-=a*a;
  20.             }else{
  21.                 v[lin][col]=0;
  22.             }
  23.             ///cer 1
  24.             if(v[lin][col]>max1)
  25.                 max1=v[lin][col];
  26.             if(v[lin][col]==k)
  27.                 cnt++;
  28.         }
  29.     }
  30.     if(cer==1)
  31.         cout<<max1<<endl<<cnt;
  32.     else{
  33.         la=v[0][0];
  34.         ci=0;
  35.         cnt=0;
  36.         max1=0;
  37.         for(lin=0;lin<n;lin++){
  38.             if(lin%2==0){
  39.                 s=0;
  40.                 e=m-1;
  41.                 mis=1;
  42.             }else{
  43.                 s=m-1;
  44.                 e=0;
  45.                 mis=-1;
  46.             }
  47.             col=s;
  48.             while(col!=e){
  49.                 if(v[lin][col]==la){
  50.                     cnt++;
  51.                 }else{
  52.                     if(cnt+1>max1 && la>0){
  53.                         ci=la;
  54.                         max1=cnt+1;
  55.                     }else if (cnt+1==max1 && la>=ci){
  56.                         ci=la;
  57.                         max1=cnt+1;
  58.                     }
  59.                     cnt=1;
  60.                 }
  61.                 la=v[lin][col];
  62.                 col+=mis;
  63.             }
  64.         }
  65.         cout<<max1<<endl<<ci;
  66.     }
  67.     return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment