[Cine are timp si chef] Imi puteti spune ce gresesc la sursa asta? ma uit de trei zile pe ea si am trstat-o in toate conditiile, pe numere mici, pe limite, cu teste random, cu teste "ne-random" si totusi nu merge... am cautat si pe net parcurgerea in spirala caci este o problema comuna, sursele de acolo nu luau mai mult de 70 de puncte... orice as face imi pica testele 5 si 9...
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("spirala.in");
ofstream g("spirala.out");
int n,m;
long C[100001];
int c=1;
long A[1500][1500];
bool checked[101][101]; /// In cazul in care elementele au fost parcurese, acestea nu vor mai fi adaugate in vectorul C
long a,b; /// Elementele care nu indeplinesc progresia
bool Verificare(){
bool ok=1;
long dif;
dif=C[2]-C[1];
for (int i=3;i<c && ok;i++)
if (C[i]-C[i-1]!=dif){
ok=0;
a=C[i];
b=C[i-1];
}
return ok;
}
void Matrice (short int x1,short int y1,short int x2,short int y2){
while (x1<=x2+1 && y1<=y2+1){
for (short int i=y1;i<=y2;i++){
if (!checked[x1][i]){
C[c]=A[x1][i];
c++;
checked[x1][i]=1;
}
}
for (short int i=x1+1;i<x2;i++){
if (!checked[i][y2]){
C[c]=A[i][y2];
c++;
checked[i][y2]=1;
}
}
for (short int i=y2;i>=y1;i--){
if (!checked[x2][i]){
C[c]=A[x2][i];
c++;
checked[x2][i]=1;
}
}
for (short int i=x2-1;i>x1;i--){
if (!checked[i][y1]){
C[c]=A[i][y1];
c++;
checked[i][y1]=1;
}
}
x1++;
y1++;
x2--;
y2--;
}
}
int main(){
f>>n>>m;
for (short int i=1;i<=n;i++)
for (short int j=1;j<=m;j++)
f>>A[i][j];
f.close();
Matrice(1,1,n,m);
if (Verificare()){
g<<"DA\n";
g<<C[c-1];
}
else{
g<<"NU\n";
g<<a<<"\n"<<b;
}
for (int i=1;i<c;i++)
cout<<C[i]<<endl;
g.close();
return 0;
}