ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1656. Far Away Kingdom's Army

Help me, please why WA#3
Posted by Harry 28 Sep 2011 01:25
Here is my code:

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,i,a[90],ans[12][12]={0},z,x,y,j;
    cin>>n;
    for(i=0; i<n*n; i++)cin>>a[i];
    sort(a,a+n*n);
             z=n*n-1; x=n/2+1; y=x;
             ans[x][y]=a[z--];
             int p=1;
                      while(z>0){
                                 ans[x-p][y]=a[z--];
                                 ans[x+p][y]=a[z--];
                                 ans[x][y-p]=a[z--];
                                 ans[x][y+p]=a[z--];
                                 for(i=y-p; i<=y+p; i++)if(ans[x-p][i]==0)ans[x-p][i]=a[z--];
                                 for(i=y-p; i<=y+p; i++)if(ans[x+p][i]==0)ans[x+p][i]=a[z--];
                                 for(i=x-p; i<=x+p; i++)if(ans[i][y-p]==0)ans[i][y-p]=a[z--];
                                 for(i=x-p; i<=x+p; i++)if(ans[i][y+p]==0)ans[i][y+p]=a[z--];
                                 p++;
                                 }
                      for(i=1; i<=n; i++){for(j=1; j<=n; j++)cout<<ans[i][j]<<" "; cout<<endl;}
    return 0;}