QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#644927#6425. Harmonious Rectanglerush-from-behind#WA 216ms3632kbC++232.4kb2024-10-16 16:03:242024-10-16 16:03:25

Judging History

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

  • [2024-10-16 16:03:25]
  • 评测
  • 测评结果:WA
  • 用时:216ms
  • 内存:3632kb
  • [2024-10-16 16:03:24]
  • 提交

answer

#include <bits/stdc++.h>
#define debug cerr << "\33[32m[" << __LINE__ << "]\33[m "
#define F(i,x,y) for(int i=(x);i<=(y);i++)
#define DF(i,x,y) for(int i=(x);i>=(y);i--)
#define ms(x,y) memset(x,y,sizeof(x))
#define SZ(x) (int)x.size()-1
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair<int,int> pii;
template<typename T> void chkmax(T &x,T y){ x=max(x,y);}
template<typename T> void chkmin(T &x,T y){ x=min(x,y);}
template<typename T> void read(T &FF){
    FF=0;int RR=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') RR=-1;
    for(;isdigit(ch);ch=getchar()) FF=(FF<<1)+(FF<<3)+ch-48;
    FF*=RR;
}
const int MOD = 1e9 + 7;
int n,m,ans,a[10][10];
void dfs(int x,int y){
    if(x>n){
        ans++;
        return;
    }
    F(i,1,3){
        a[x][y]=i;
        bool fl=1;
        F(p,1,x-1){
            F(q,1,y-1){
                if((a[p][q]==a[p][y]&&a[x][q]==a[x][y])||
                (a[p][q]==a[x][q]&&a[p][y]==a[x][y]))
                fl=0;
            }
            if(!fl) break;
        }
        if(fl){
            if(y==m) dfs(x+1,1);
            else dfs(x,y+1);
        }
    }
}
const int P=1e9+7;
int qmi(int x,int y){
    int res=1;for(;y;y>>=1){ if(y&1) res=1ll*res*x%P;x=1ll*x*x%P;}
    return res;
}
int query(int n, int m) {
	ans=0;
	::n = n, ::m = m;
			if(n>m)swap(n,m);
			int tot=qmi(3,n*m);
			if(n==1) return 0;
			else if(m>7){
				return tot;
			}
			else if(n==2||n==3){
				if(m>7) return tot;
				else{
					dfs(1,1);
					return (tot - ans + MOD) % MOD;
				}
			}
			else if(n==4){
				if(m>6) return tot;
				else{
					dfs(1,1);
					return (tot - ans + MOD) % MOD;
				}
			}
			else if(n==5){
				if(m>5) return tot;
				else{
					dfs(1,1);
					return (tot - ans + MOD) % MOD;
				}
			}
			else return tot;
}
int aa[10][10];
int main(){
    // freopen("1.out","w",stdout);
    // n=6,m=6;
    // dfs(1,1);
    // cout<<ans<<'\n';
    // exit(0);
	F(n, 1, 7)
		F(m, n, 7) {
			aa[n][m] = query(n, m);
		}
	int _; cin >> _;
	while (_--) {
		int n, m;
		cin >> n >> m;
		if (n >= m) swap(n, m);
		if (m > 7) {
			cout << qmi(3,n*m) << '\n';
		} else {
			// debug << qmi(3, n*m) << " " << aa[n][m] << endl;
			cout << aa[n][m] << '\n';
		}
	}
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 209ms
memory: 3632kb

input:

3
1 4
2 2
3 3

output:

0
15
16485

result:

ok 3 number(s): "0 15 16485"

Test #2:

score: -100
Wrong Answer
time: 216ms
memory: 3572kb

input:

10000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 6...

output:

0
0
0
0
0
0
0
6561
19683
59049
177147
531441
1594323
4782969
14348907
43046721
129140163
387420489
162261460
486784380
460353133
381059392
143178169
429534507
288603514
865810542
597431612
792294829
376884473
130653412
391960236
175880701
527642103
582926302
748778899
246336683
739010049
217030133
6...

result:

wrong answer 8th numbers differ - expected: '0', found: '6561'