Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <math.h>
- using namespace std;
- ifstream cin("soricel.in");
- ofstream cout("soricel.out");
- int v[200][200],aux[200][200];
- int main()
- {
- int cer,n,m,k,lin,col,max1,cnt,a,la,s,e,mis,ci,cd,ld;
- cin>>cer>>n>>m>>k;
- max1=1;
- cnt=0;
- for(lin=0;lin<n;lin++){
- for(col=0;col<m;col++){
- cin>>v[lin][col];
- if(v[lin][col]>1){
- a=(int)sqrt(v[lin][col]-1);
- aux[lin][col]=a*a;
- v[lin][col]-=a*a;
- }else{
- v[lin][col]=0;
- }
- ///cer 1
- if(v[lin][col]>max1)
- max1=v[lin][col];
- if(v[lin][col]==k)
- cnt++;
- }
- }
- if(cer==1)
- cout<<max1<<" "<<cnt;
- else{
- la=v[0][0];
- ld=aux[0][0];
- ci=cd=max1=0;
- cnt=1;
- for(lin=0;lin<n;lin++){
- if(lin%2==0){
- s=0;
- e=m;
- mis=1;
- }else{
- s=m-1;
- e=-1;
- mis=-1;
- }
- if(lin==0)
- col=1;
- col=s;
- if(lin==0)
- col=1;
- while(col!=e){
- if(v[lin][col]==la){
- cnt++;
- }else{
- if(cnt>max1 && la>0){
- ci=la;
- cd=ld;
- max1=cnt;
- }else if (cnt==max1 && ld>ci && la>0){
- cd=ld;
- ci=la;
- }else if(cnt==max1 && ld==cd && la>ci){
- ci=la;
- }
- cnt=1;
- }
- la=v[lin][col];
- ld+=aux[lin][col];
- col+=mis;
- }
- }
- if(cnt>max1 && la>0){
- ci=la;
- cd=ld;
- max1=cnt;
- }else if (cnt==max1 && ld>ci && la>0){
- cd=ld;
- ci=la;
- }else if(cnt==max1 && ld==cd && la>ci){
- ci=la;
- }
- cout<<max1<<" "<<ci;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement