Riesco a fare 65/100 punti ma non riesco a prendere l’ultima subtask per 0,11 secondi, qualcuno sa cosa potrei migliorare e/o ottimizzare del mio programma?
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
//typedef pair<int, int> P;
int numeroFin=100000;
int rip=0;
int power=1;
int num=0;
int num2=0;
map <int, int> order;
void something(){
order[num]++;
order[num2]++;
if(order[num]==rip && num/1000 != 0){
numeroFin=min(numeroFin, num);
}else if(order[num]>rip && num/1000 != 0){
rip=order[num];
numeroFin=num;
}
if(order[num2]==rip && num2/1000 != 0){
numeroFin=min(numeroFin, num2);
}else if(order[num2]>rip && num2/1000 != 0){
rip=order[num2];
numeroFin=num2;
}
num=0; num2=0;
power=1;
}
//ios_base::sync_with_stdio(false);
int main(){
ios_base::sync_with_stdio(false);
int n, m;
cin>>n>>m;
int** x = new int*[n];
for(int i = 0; i < n; ++i){
x[i] = new int[m];
string numero;
cin>>numero;
for(int j = 0; j<m; ++j){
x[i][j] = numero[0] -48;
numero.erase(numero.begin());
//sinistra
if(j-3>=0){
for(int y=0; y<4; ++y){
num+=x[i][j-y]*power;
num2+=x[i][j-y]*(1000/power);
power*=10;
}
something();
}
//alto
if(i-3>=0){
for(int y=0; y<4; ++y){
num+=x[i-y][j]*power;
num2+=x[i-y][j]*(1000/power);
power*=10;
}
something();
}
//destro-alto
if(j+3<m && i-3>=0){
for(int y=0; y<4; ++y){
num+=x[i-y][j+y]*power;
num2+=x[i-y][j+y]*(1000/power);
power*=10;
}
something();
}
//sinistra-alto
if(j-3>=0 && i-3>=0){
for(int y=0; y<4; ++y){
num+=x[i-y][j-y]*power;
num2+=x[i-y][j-y]*(1000/power);
power*=10;
}
something();
}
}
}
cout<<numeroFin<<" "<<rip;
}