P2105 K皇后
这道题 使用以下的代码不吸氧获得50pts:
记录
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e4+5;
bool h[N],l[N];
bool dj1[N*2],dj2[N*2];
int n,m,k;
int main(){
scanf("%d %d %d",&n,&m,&k);
int x,y;
for(int i=1;i<=k;i++){
scanf("%d %d",&x,&y);
h[x]=true;
l[y]=true;
dj1[(x+y)-1]=true;
dj2[x+n-y]=true;
}
int ans=0;
for(int i=1;i<=n;i++){
if(h[i]) continue;
for(int j=1;j<=m;j++){
if(h[i]||l[j]||dj1[i+j-1]||dj2[i+n-j])continue;
ans++;
}
}
cout<<ans;
return 0;
}
而将if(h[i]||l[j]||dj1[i+j-1]||dj2[i+n-j])continue;
改变成if(h[i]|l[j]|dj1[i+j-1]|dj2[i+n-j])continue;
反而40pts,TLE#2
难道位运算比||还慢?(本蒟蒻印象中位运算很快的啊)
但是两份代码同时开O2改后的代码比原代码总共快1000ms+
求dalao解答