QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244195#1273. It's All SquaresPhantomThreshold#RE 1ms3464kbC++202.9kb2023-11-08 21:51:362023-11-08 21:51:36

Judging History

你现在查看的是最新测评结果

  • [2023-11-08 21:51:36]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3464kb
  • [2023-11-08 21:51:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		int n,m,q;
		cin>>n>>m>>q;
		vector<vector<int>> a(n+5,vector<int>(m+5));
		vector<vector<int>> hc(n+5,vector<int>(m+5));
		vector<vector<int>> vc(m+5,vector<int>(n+5));
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				cin>>a[i][j];
		map<int,int> mp;
		int id=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				auto &t=mp[a[i][j]];
				if(not t)
				{
					t=++id;
				}
				hc[i][j]=t;
			}
		}
		mp.clear();
		id=0;
		for(int j=1;j<=m;j++)
		{
			for(int i=1;i<=n;i++)
			{
				auto &t=mp[a[i][j]];
				if(not t)
				{
					t=++id;
				}
				vc[i][j]=t;
			}
		}
		vector<int> cnt(n*m+5),vis(n*m+5,q);
		while(q--)
		{
			int x,y;
			string s;
			cin>>x>>y>>s;
			int ud=0,lr=0;
			int area=0;
			for(auto ch:s)
			{
				if(ch=='U')
				{
					ud++;
					area+=x;
					y++;
				}
				else if(ch=='D')
				{
					ud++;
					area-=x;
					y--;
				}
				else if(ch=='L')
				{
					lr++;
					x--;
				}
				else
				{
					lr++;
					x++;
				}
			}
//			cerr<<"!! "<<area<<endl;
			if(area<0)
			{
				reverse(s.begin(),s.end());
				for(auto &ch:s)
				{
					if(ch=='U')ch='D';
					else if(ch=='D')ch='U';
					else if(ch=='L')ch='R';
					else ch='L';
				}
			}
			int ans=0;
			if(ud<=lr)
			{
				//use v
				for(auto ch:s)
				{
//					cerr<<"go "<<ch<<endl;
					if(ch=='U')
					{
						y++;
						for(int i=x;i>=1;i--)
						{
//							cerr<<"add "<<i<<' '<<y<<endl;
							if(vis[vc[y][i]]!=q)vis[vc[y][i]]=q,cnt[vc[y][i]]=0;
							cnt[vc[y][i]]++;
							if(cnt[vc[y][i]]==1)ans++;
						}
					}
					else if(ch=='D')
					{
						for(int i=x;i>=1;i--)
						{
//							cerr<<"del "<<i<<' '<<y<<endl;
							if(vis[vc[y][i]]!=q)vis[vc[y][i]]=q,cnt[vc[y][i]]=0;
							cnt[vc[y][i]]--;
							if(cnt[vc[y][i]]==0)ans--;
						}
						y--;
					}
					else if(ch=='L')
					{
						x--;
					}
					else
					{
						x++;
					}
				}
			}
			else
			{
				for(auto ch:s)
				{
//					cerr<<"hgo "<<ch<<endl;
					if(ch=='R')
					{
						x++;
						for(int i=y;i>=1;i--)
						{
//							cerr<<"del "<<x<<' '<<i<<' '<<hc[x][i]<<endl;
							if(vis[hc[x][i]]!=q)vis[hc[x][i]]=q,cnt[hc[x][i]]=0;
							cnt[hc[x][i]]--;
							if(cnt[hc[x][i]]==0)ans--;
						}
					}
					else if(ch=='L')
					{
						for(int i=y;i>=1;i--)
						{
//							cerr<<"add "<<x<<' '<<i<<' '<<hc[x][i]<<' '<<cnt[hc[x][i]]<<endl;
							if(vis[hc[x][i]]!=q)vis[hc[x][i]]=q,cnt[hc[x][i]]=0;
							cnt[hc[x][i]]++;
							if(cnt[hc[x][i]]==1)ans++;
						}
						x--;
					}
					else if(ch=='D')
					{
						y--;
					}
					else
					{
						y++;
					}
				}
			}
			cout<<ans<<"\n";
		}
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3464kb

input:

1
3 3 2
1 2 3
1 1 2
7 8 9
0 0 RRRUUULLLDDD
0 0 RRUULLDD

output:

6
2

result:

ok 2 lines

Test #2:

score: -100
Runtime Error

input:

10
353 304 4000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98...

output:


result: