QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#93924#5520. Distance ParitiesAsad_BinWA 0ms3360kbC++174.3kb2023-04-04 03:46:002023-04-04 03:46:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-04 03:46:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3360kb
  • [2023-04-04 03:46:00]
  • 提交

answer

// . . . Bismillahir Rahmanir Rahim . . .
 
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#ifndef ONLINE_JUDGE
#define dbg_out cout
#define debug(...) dbg_out << "DBG )> "; __f(#__VA_ARGS__, __VA_ARGS__);
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> pr) { out << "{ " << pr.first << ", " << pr.second << " }"; return out; }
template<typename T1> ostream& operator<<(ostream& out, vector<T1> vec) { out << "{ "; for (auto &x: vec) out << x << ", "; out << "}"; return out; }
template<typename T1, size_t size> ostream& operator<<(ostream& out, array<T1, size> arr) { out << "{ "; for (auto &x: arr) out << x << ", "; out << "}"; return out; }
template<typename T1, typename T2> ostream& operator<<(ostream& out, map<T1, T2> mp) { out << "{ ";for (auto &x: mp) out << x.first << ": " << x.second <<  ", "; out << "}"; return out; }
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { while (isspace(name[0])) name++; (isalpha(name[0]) || name[0] == '_') ? dbg_out << name << ": " << arg1 << "\n" : dbg_out << arg1 << "\n"; dbg_out.flush();}
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) { const char *comma = strchr(names + 1, ','); while (isspace(names[0])) names++; (isalpha(names[0]) || names[0] == '_') ? dbg_out.write(names, comma - names) << ": " << arg1 << " | " : dbg_out << arg1 << " | "; __f(comma + 1, args...);}
#else
#define debug(...)
#endif
 
ll gcd(ll a, ll b){ while (b){ a %= b; swap(a, b);} return a;}
ll lcm(ll a, ll b){ return (a/gcd(a, b)*b);}
ll ncr(ll a, ll b){ ll x = max(a-b, b), ans=1; for(ll K=a, L=1; K>=x+1; K--, L++){ ans = ans * K; ans /= L;} return ans;}
ll bigmod(ll a,ll b,ll mod){ if(b==0){ return 1;} ll tm=bigmod(a,b/2,mod); tm=(tm*tm)%mod; if(b%2==1) tm=(tm*a)%mod; return tm;}
ll egcd(ll a,ll b,ll &x,ll &y){ if(a==0){ x=0; y=1; return b;} ll x1,y1; ll d=egcd(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; return d;}
ll modpow(ll a,ll p,ll mod) {ll ans=1;while(p){if(p%2)ans=(ans*a)%mod;a=(a*a)%mod;p/=2;} return ans;}
ll inverse_mod(ll n,ll mod) {return modpow(n,mod-2,mod);}


const ll mod = 998244353;
vector<vector<ll> > ara;
vector<vector<vector<ll > > > dp;
int n, m;

int calc(int i, int j, int bit)
{
	if(i >= n || j >= m) return 0;
	if(ara[i][j] != -1 && ara[i][j] != bit) return 0;
	if(i == n-1 && j == m-1) return 1;
	
	//if(dp[i][j][bit] != -1) return dp[i][j][bit];
	
	int ans = 0;
	
	if(!bit) ans += calc(i+1, j, 0) + calc(i, j+1, 0);
	ans %= mod;
	ans += calc(i+1, j, 1) + calc(i+1, j, 1);
	ans %= mod;
	
	return dp[i][j][bit] = ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int t; cin >> t;
	while(t--){
		cin >> n >> m;
		
		ara.resize(n); dp.resize(n);
		for(int K = 0; K < n; K++) {
			ara[K].resize(m); dp[K].resize(m, vector<ll> (2, -1));
		}
		
		for(int K = 0; K < n; K++){
			for(int L = 0; L < m; L++) cin >> ara[K][L];
		}
		
		bool ok = 1;
		for(int K = 0; K < n; K++){
			for(int L = 0; L < m; L++){
				if(ara[K][L] == -1) continue;
				
				ara[K][L] -= K+L+1;
				if(ara[K][L] < 0 || ara[K][L] > 1) {
					ok = 0;
					break;
				}
			}
			if(!ok) break;
		}
		if(!ok){
			cout << 0 << "\n";
			continue;
		}
		
		
		for(int K = 0; K < n; K++){
			for(int L = 0; L < m; L++){
				if(ara[K][L] == 1){
					if(K+1 >= n) {}
					else if(!ara[K+1][L]){
						ok = 0;
						break;
					}
					else{
						ara[K+1][L] = 1;
					}
					
					if(L+1 >= m){}
					else if(!ara[K][L+1]){
						ok = 0;
						break;
					}
					else {
						ara[K][L+1] = 1;
					}
				}
			}
			if(!ok) break;
		}
		
		if(!ok) {
			cout << 0 << "\n";
			continue;
		}
		//cout << n << ' ' << m << "\n";;
		
		for(int K = n-1; K >= 0; K--){
			for(int L = m-1; L >= 0; L--){
				if(!ara[K][L]){
					if(K-1 < 0) {}
					else if(ara[K-1][L] == 1){
						ok = 0;
						break;
					}
					else{
						ara[K-1][L] = 0;
					}
					
					if(L-1 < 0){}
					else if(ara[K][L-1] == 1){
						ok = 0;
						break;
					}
					else {
						ara[K][L-1] = 0;
					}
				}
			}
			if(!ok) break;
		}
		
		if(!ok) {
			cout << 0 << "\n";
			continue;
		}
		
		//for(int K = 0; K < n; K++) {
			//for(int L = 0; L < m; L++) cout << ara[K][L] << ' ';
			//cout << "\n";
		//}
		
		cout << (calc(0, 0, 0) + calc(0, 0, 1))%mod << "\n";
	}
	
	return 0;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3360kb

input:

3
3
011
101
110
4
0100
1000
0001
0010
5
01010
10101
01010
10101
01010

output:

0
0
0

result:

wrong answer Token parameter [name=yes/no] equals to "0", doesn't correspond to pattern "[yY][eE][sS]|[nN][oO]" (test case 1)