Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int n,m,t;
- cin>>n>>m>>t;
- int *a=new int [n*m];
- int b[100000],k=0;
- int pos[300][300]={0};
- for(int i=0;i<n*m;i++){
- cin>>a[i];
- if(a[i]!=0){
- b[k]=a[i];
- k++;
- }
- }
- stable_sort(b,b+k);
- if(t+1<k){
- cout<<"Wrong Board";
- return 0;
- }
- int x1=-1,y1=-1;
- for(int i=0;i<k;i++){
- int pos1=(find(a,a+n*k,b[i])-a);
- int y=(pos1/m),x=(pos1%m);
- if(i>0){
- if((abs(x1-x)!=abs(y1-y))&& (x1!=x) && (y1!=y)){
- cout<<"Wrong Board";
- return 0;
- }
- else{
- pos[y][x]=(i+1);
- }
- }
- pos[y][x]=(i+1);
- y1=y,x1=x;
- }
- for(int i=0;i<n;i++){
- for(int j=0;j<m;j++){
- cout<<pos[i][j]<<" ";
- }
- cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement