Advertisement
Patrickmeme

Soricel - 85p

Mar 23rd, 2023
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 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],aux[200][200];
  7.  
  8. int main()
  9. {
  10.     int cer,n,m,k,lin,col,max1,cnt,a,la,s,e,mis,ci,cd,ld;
  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.  
  18.             if(v[lin][col]>1){
  19.                 a=(int)sqrt(v[lin][col]-1);
  20.                 aux[lin][col]=a*a;
  21.                 v[lin][col]-=a*a;
  22.             }else{
  23.                 v[lin][col]=0;
  24.             }
  25.             ///cer 1
  26.             if(v[lin][col]>max1)
  27.                 max1=v[lin][col];
  28.             if(v[lin][col]==k)
  29.                 cnt++;
  30.         }
  31.     }
  32.     if(cer==1)
  33.         cout<<max1<<" "<<cnt;
  34.     else{
  35.         la=v[0][0];
  36.         ld=aux[0][0];
  37.         ci=cd=max1=0;
  38.         cnt=1;
  39.         for(lin=0;lin<n;lin++){
  40.             if(lin%2==0){
  41.                 s=0;
  42.                 e=m;
  43.                 mis=1;
  44.             }else{
  45.                 s=m-1;
  46.                 e=-1;
  47.                 mis=-1;
  48.             }
  49.             if(lin==0)
  50.                 col=1;
  51.             col=s;
  52.             if(lin==0)
  53.                 col=1;
  54.             while(col!=e){
  55.                 if(v[lin][col]==la){
  56.                     cnt++;
  57.                 }else{
  58.                     if(cnt>max1 && la>0){
  59.                         ci=la;
  60.                         cd=ld;
  61.                         max1=cnt;
  62.                     }else if (cnt==max1 && ld>ci && la>0){
  63.                         cd=ld;
  64.                         ci=la;
  65.                     }else if(cnt==max1 && ld==cd && la>ci){
  66.                         ci=la;
  67.                     }
  68.                     cnt=1;
  69.                 }
  70.                 la=v[lin][col];
  71.                 ld+=aux[lin][col];
  72.                 col+=mis;
  73.             }
  74.         }
  75.         if(cnt>max1 && la>0){
  76.             ci=la;
  77.             cd=ld;
  78.             max1=cnt;
  79.         }else if (cnt==max1 && ld>ci && la>0){
  80.             cd=ld;
  81.             ci=la;
  82.         }else if(cnt==max1 && ld==cd && la>ci){
  83.             ci=la;
  84.         }
  85.         cout<<max1<<" "<<ci;
  86.     }
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement