Submission #422312

#TimeUsernameProblemLanguageResultExecution timeMemory
422312errorgornNavigation 2 (JOI21_navigation2)C++17
100 / 100
1251 ms972 KiB
#include "Anna.h"

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

namespace {
	int n,k;
	vector<int> R,C;
	
	int grid[105][105];
	
	const ii coord[]={{-1,-1},{-1,0},{-1,1},
					  {0,-1},{0,0},{0,1},
					  {1,-1},{1,0},{1,1}};
} // namespace

set<int> can(int i,int j){
	set<int> s;
	
	rep(x,0,n) rep(y,0,n){
		int num=((x+i)%3)*3+((y+j)%3);
		
		if (num==0) ;
		else if (num==8) ;
		else{
			num--;
			rep(z,0,9) if (x==R[num]+coord[z].fi && y==C[num]+coord[z].se){
				s.insert(z+1);
			}
		}
	}
	
	return s;
}

void Anna(int N, int K, std::vector<int> RR, std::vector<int> CC) {
	n=N,k=K;
	R=RR,C=CC;
	memset(grid,0,sizeof(grid));
	
	int dx,dy;
	int useless;
	rep(x,0,3) rep(y,0,3) {
		auto s=can(x,y);
		
		if (!s.count(9)){
			dx=x,dy=y;
			rep(z,1,10) if (!s.count(z)){
				useless=z;
				break;
			}
		}
	}
	
	//cout<<"useless: "<<useless<<endl;
	//cout<<"d: "<<dx<<" "<<dy<<endl;
	
	rep(x,0,n) rep(y,0,n){
		int num=((x+dx)%3)*3+((y+dy)%3);
		
		if (num==0) grid[x][y]=13;
		else if (num==8) grid[x][y]=-1;
		else{
			num--;
			rep(z,0,9) if (x==R[num]+coord[z].fi && y==C[num]+coord[z].se){
				grid[x][y]=z+1;
			}
			if (grid[x][y]==0){
				if (C[num]<y-1) grid[x][y]=9;
				else if (y+1<C[num]) grid[x][y]=10;
				else if (R[num]<x-1) grid[x][y]=11;
				else if (x+1<R[num]) grid[x][y]=12;
			}
		}
	}
	
	/*
	rep(x,0,n){
		rep(y,0,n) cout<<grid[x][y]<<" "; cout<<endl;
	}
	//*/
	
	rep(x,0,n) rep(y,0,n) if (grid[x][y]>=useless) grid[x][y]--;
	rep(x,0,n) rep(y,0,n) if (grid[x][y]==-1) grid[x][y]=useless;
	
	/*
	rep(x,0,n){
		rep(y,0,n) cout<<grid[x][y]<<" "; cout<<endl;
	}
	//*/
	
	rep(x,0,n) rep(y,0,n) SetFlag(x,y,grid[x][y]);
}
#include "Bruno.h"

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

namespace {
	int k;
	
	const ii coord[]={{-1,-1},{-1,0},{-1,1},
					  {0,-1},{0,0},{0,1},
					  {1,-1},{1,0},{1,1}};
} // namespace

std::vector<int> Bruno(int K, std::vector<int> value) {
	k=K;
	
	int px,py;
	rep(x,0,9) if (value[x]==12){
		px=x/3,py=x%3;
	}
	
	int useless=value[(px+2)%3*3+(py+2)%3];
	//cout<<"b useless: "<<useless<<endl;
	
	vector<int> ans;
	
	rep(x,0,k){
		int dx=(px+(x+1)/3)%3;
		int dy=(py+(x+1))%3;
		
		int i=dx*3+dy;
		
		if (value[i]>=useless) value[i]++;
		
		if (value[i]<=8){
			int ddx=(dx-1)-coord[value[i]-1].fi;
			int ddy=(dy-1)-coord[value[i]-1].se;
			
			//cout<<"???: "<<value[i]<<endl;
			//cout<<x<<" "<<ddx<<" "<<ddy<<endl;
			
			if (ddy>0) ans.pub(0);
			else if (ddy<0) ans.pub(1);
			else if (ddx>0) ans.pub(2);
			else if (ddx<0) ans.pub(3);
			else ans.pub(4);
		}
		else if (value[i]==9) ans.pub(1);
		else if (value[i]==10) ans.pub(0);
		else if (value[i]==11) ans.pub(3);
		else if (value[i]==12) ans.pub(2);
	}
	
	//for (auto &it:ans) cout<<it<<" "; cout<<endl;
	
	return ans;
}

Compilation message (stderr)

Anna.cpp: In function 'void Anna(int, int, std::vector<int>, std::vector<int>)':
Anna.cpp:100:54: warning: 'useless' may be used uninitialized in this function [-Wmaybe-uninitialized]
  100 |  rep(x,0,n) rep(y,0,n) if (grid[x][y]==-1) grid[x][y]=useless;
      |                                            ~~~~~~~~~~^~~~~~~~
Anna.cpp:75:27: warning: 'dy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |   int num=((x+dx)%3)*3+((y+dy)%3);
      |                         ~~^~~~
Anna.cpp:75:14: warning: 'dx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |   int num=((x+dx)%3)*3+((y+dy)%3);
      |            ~~^~~~

Bruno.cpp: In function 'std::vector<int> Bruno(int, std::vector<int>)':
Bruno.cpp:45:13: warning: 'py' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |   int dy=(py+(x+1))%3;
      |          ~~~^~~~~~~
Bruno.cpp:44:13: warning: 'px' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   int dx=(px+(x+1)/3)%3;
      |          ~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...