CF1644D Cross Coloring
CF1644D Cross Coloring
题意:
在一个
做法:
因为后染的色会覆盖先染的色,所以最后染的色一定不会被覆盖,不需要处理被覆盖的情况,所以我们从后向前枚举每次操作,如果当前列和当前行都已经被染色,那么这次操作会被后面的操作覆盖,对结果没有影响,不需要统计,否则共有
特判:
当网格全部被覆盖,即
时间复杂度
记得开 long long
!
代码:
#include<iostream> #define int long long using namespace std; int T; int a[200010], b[200010]; bool x[200010], y[200010]; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f; } int maxx(int x, int y) { return x > y ? x : y; } signed main() { T = read(); while(T--) { int n=read(), m=read(), k=read(), q=read(); int xf=0, yf=0, ans=1, c=maxx(n, m); for(int i=1; i<=c; i++) { x[i] = y[i] = false; } for(int i=1; i<=q; i++) { a[i] = read(); b[i] = read(); } for(int i=q; i>=1; i--) { if(xf == n || yf == m) { break; } bool flag = false; if(x[a[i]] == false) { x[a[i]] = true; flag = true; xf ++; } if(y[b[i]] == false) { y[b[i]] = true; flag = true; yf ++; } if(flag) { ans *= k; ans %= 998244353; } } cout << ans << '\n'; } return 0; }
本文作者:gctiruct
本文链接:https://www.cnblogs.com/gctiruct/p/17810745.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步