QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#237159#6836. A Plus B ProblemAndy#WA 203ms11792kbC++172.2kb2023-11-04 13:21:222023-11-04 13:21:23

Judging History

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

  • [2023-11-04 13:21:23]
  • 评测
  • 测评结果:WA
  • 用时:203ms
  • 内存:11792kb
  • [2023-11-04 13:21:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
	char c=getchar();
	int f=1,x=0;
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return f*x;
}
const int N=1e6+5;
char s[N];
int n,q;
int num[4][N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>q;
	cin>>s+1;
	for(int i=1;i<=n;i++)
		num[1][i]=s[i]-'0';
	cin>>s+1;
	for(int i=1;i<=n;i++)
		num[2][i]=s[i]-'0';
	int res=0;
	set<int> v;
	for(int i=n;i>=1;i--)
	{
		if(num[2][i]+num[1][i]!=9)
			v.insert(i);
		if(num[1][i]+num[2][i]+res>=10)
		{
			num[3][i]=(num[1][i]+num[2][i]+res)%10;
			res=1;
		}
		else
		{
			num[3][i]=num[1][i]+num[2][i]+res;
			res=0;
		}
		//cout<<num[3][i]<<' ';
	}
    v.insert(0);
	int r,c,d;
	int ans=0;
	while(q--)
	{
		cin>>r>>c>>d;
	    auto u=v.upper_bound(c);
		int flag=0;
		if(u==v.end());
		else
		{
			if(num[1][*u]+num[2][*u]>9)flag=1;
		}
		if(num[r][c]==d)
		{
			cout<<(num[1][c]+num[2][c]+flag)%10<<" 0\n";
		}
		if(num[1][c]+num[2][c]+flag<=9)
		{
			if(num[3-r][c]+d+flag<=9)
			{
				num[3][c]=num[3-r][c]+d+flag;
				num[r][c]=d;
				cout<<num[3][c]<<" 2\n";
				if(num[1][c]+num[2][c]==9)v.erase(c);
				else v.insert(c);
				continue;
			}
			else
			{
				ans=2;
				//cout<<num[3-r][c]<<' '<<d<<endl;
				num[3][c]=(num[3-r][c]+d+flag)%10;
				num[r][c]=d;
				if(num[1][c]+num[2][c]==9)v.erase(c);
				else v.insert(c);
				auto bef=v.lower_bound(c);
				bef--;
				if(*bef)
					ans+=c-*bef;
				else ans+=c-*bef-1;
				cout<<num[3][c]<<' '<<ans<<'\n';
				continue;
			}
		}
		else
		{
			if(num[3-r][c]+d+flag<=9)
			{
				ans=2;
				num[3][c]=num[3-r][c]+d+flag;
				num[r][c]=d;
				if(num[1][c]+num[2][c]==9)
					v.erase(c);
				else v.insert(c);
				auto bef=v.lower_bound(c);
				bef--;
				if(*bef)
					ans+=c-*bef;
				else ans+=c-*bef-1;
				cout<<num[3][c]<<' '<<ans<<'\n';
				continue;
			}
			else
			{
				ans=2;
				num[3][c]=(num[3-r][c]+d+flag)%10;
				num[r][c]=d;
				if(num[1][c]+num[2][c]==9)v.erase(c);
				else v.insert(c);
				cout<<num[3][c]<<' '<<ans<<'\n';
			}
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9680kb

input:

5 5
01234
56789
2 1 0
2 2 1
2 3 2
2 4 3
2 5 4

output:

0 2
3 2
5 3
7 3
8 3

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 11792kb

input:

1 1
1
1
1 1 9

output:

0 2

result:

ok single line: '0 2'

Test #3:

score: -100
Wrong Answer
time: 203ms
memory: 11724kb

input:

10 1000000
6869373857
3130626142
1 9 2
1 10 0
2 7 6
1 1 0
1 7 6
2 10 4
2 3 9
2 4 2
2 4 4
2 7 0
1 2 4
1 9 8
1 3 7
1 7 1
1 1 5
2 1 6
1 3 5
2 5 8
2 6 5
1 6 3
1 3 8
2 4 2
2 6 3
2 2 6
1 10 9
2 1 1
2 5 4
1 1 8
2 4 0
1 9 1
1 1 8
2 4 2
2 9 2
1 10 3
1 8 9
1 4 6
2 3 0
1 1 6
1 7 1
1 10 9
2 4 4
2 5 9
2 1 8
1 9 ...

output:

6 2
2 2
9 0
9 2
3 2
2 8
4 2
6 2
2 2
4 2
6 5
6 3
2 4
7 2
2 2
8 2
1 2
5 2
1 3
2 3
8 3
8 2
2 2
6 2
1 3
3 3
7 2
7 3
0 2
9 3
6 4
0 0
0 2
1 3
4 2
7 3
0 3
8 3
8 3
8 2
2 0
2 2
3 3
0 3
2 3
5 2
9 2
4 2
8 2
3 3
5 3
3 2
5 0
5 2
4 2
3 2
1 2
4 2
7 3
0 2
5 2
6 2
0 3
4 2
4 2
3 2
5 3
6 3
3 0
3 2
8 2
9 3
9 3
1 2
1 4
...

result:

wrong answer 4th lines differ - expected: '3 2', found: '9 2'