QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87811#5237. Drybling Bajtessiego [B]anhduc27010 0ms0kbC++233.1kb2023-03-14 13:07:172023-03-14 13:07:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-14 13:07:19]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-03-14 13:07:17]
  • 提交

answer

/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#define int long long 
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "BAJ"  
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dpl[605][605];
int dpr[605][605];
int nxt[605][605][2];
int pref[605][605][2];
int suf[605][605][2];
int s[605];
int last[605][2];
string k[605];
void computel(int id){
	memset(dpl,0,sizeof(dpl));
	dpl[0][0]=1;
	for(int i=0;i<k[id].size();i++){
		for(int j=0;j<k[id].size();j++){
			dpl[nxt[id][i][1]][j+1]+=dpl[i][j];
			dpl[nxt[id][i][1]][j+1]%=mod;
			if(j>0){
				dpl[nxt[id][i][0]][j-1]+=dpl[i][j];
				dpl[nxt[id][i][0]][j-1]%=mod;
			}
		}
	}
	for(int i=0;i<k[id].size();i++){
		for(int j=0;j<k[id].size();j++){
			if(i>0 && j==0){
				s[id]+=dpl[i][j];
				s[id]%=mod;
			}
			if(nxt[id][i][0]==k[id].size()){
				pref[id][j][0]+=dpl[i][j];
				pref[id][j][0]%=mod;
			}
			if(nxt[id][i][1]==k[id].size()){
				pref[id][j][1]+=dpl[i][j];
				pref[id][j][1]%=mod;
			}
		}
	}
}
int computer(int id,int pos,int sum){
	if(sum<0 || sum>600 )return 0;
	if(pos==k[id].size()){
		return 0;
	}
	if(dpr[pos][sum]!=-1){
		return dpr[pos][sum];
	}
	if(sum==0){
		dpr[pos][sum]=1;
	}
	else dpr[pos][sum]=0;
	dpr[pos][sum]+=computer(id,nxt[id][pos][1],sum+1);
	dpr[pos][sum]+=computer(id,nxt[id][pos][0],sum-1);
	dpr[pos][sum]%=mod;
	return dpr[pos][sum];
}
void computer(int id){
	memset(dpr,-1,sizeof(dpr));
	for(int j=0;j<=600;j++){
		suf[id][j][0]=computer(id,nxt[id][0][0],j-1);
		suf[id][j][1]=computer(id,nxt[id][0][1],j+1);
	}
}
signed main()
{
	cin.tie(0),cout.tie(0)->sync_with_stdio(0);
    freopen(task".inp" , "r" , stdin);
    freopen(task".out" , "w" , stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
    	string q;
    	cin>>q;
    	q="$"+q;
    	k[i]=q;
    	nxt[i][q.size()][0]=q.size();
    	nxt[i][q.size()][1]=q.size();
    	last[i][0]=q.size();
    	last[i][1]=q.size();
    	for(int j=q.size()-1;j>=0;j--){
    		nxt[i][j][1]=last[i][1];
    		nxt[i][j][0]=last[i][0];

    		if(q[j]=='L'){
    			last[i][1]=j;
    		}
    		else if(q[j]=='P'){
    			last[i][0]=j;
    		}

    	}
    	computel(i);
    	computer(i);
    } 
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=n;j++){
    		int sum=s[i];
    		for(int z=0;z<=600;z++){
    			sum+=pref[i][z][0]*suf[j][z][0];
    			sum+=pref[i][z][1]*suf[j][z][1];
    			sum%=mod;
    		}
    		cout<<sum<<" ";
    	}
    	cout<<"\n";
    }
    return 0;
}


详细

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 0
Dangerous Syscalls

input:

1
L

output:


result:


Subtask #2:

score: 0
Dangerous Syscalls

Test #9:

score: 0
Dangerous Syscalls

input:

7
PLP
PLP
PLP
PLP
PLP
PLP
PLP

output:


result:


Subtask #3:

score: 0
Dangerous Syscalls

Test #15:

score: 0
Dangerous Syscalls

input:

1
PLLLPLPLPPPPLLLLLLLLLLLLLPPPPPLPLPLLLPPLPPPPPLLPLLLLPLLPLPLPPLLPPPLLLPLPPLLLPLPPPLLLLPLPPPLLLLPPLPLLPPPPLPPLPLPLPPPLPLPPPLPPPPPPLPPLPPLLPPLPPPPPLLPLLPPPPPPPPPPLPPLLPLPPPLLPLLLLLLPPLPPLPPLLPLLPLLLLLPPL

output:


result:


Subtask #4:

score: 0
Dangerous Syscalls

Test #22:

score: 0
Dangerous Syscalls

input:

63
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLPLPL
PLP...

output:


result:


Subtask #5:

score: 0
Dangerous Syscalls

Test #28:

score: 0
Dangerous Syscalls

input:

127
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
PLPLPLP
...

output:


result:


Subtask #6:

score: 0
Dangerous Syscalls

Test #35:

score: 0
Dangerous Syscalls

input:

255
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL
PLPLPLPL...

output:


result:


Subtask #7:

score: 0
Dangerous Syscalls

Test #42:

score: 0
Dangerous Syscalls

input:

511
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPLPLP
PLPLPL...

output:


result:


Subtask #8:

score: 0
Dangerous Syscalls

Test #49:

score: 0
Dangerous Syscalls

input:

500
PPPLLLPPPPPPPPLLLLLLPLPLLPPPLLPLLPLPLLLPPLLLPPLPPLLPPPLLLLPPPLLLPPPPPLLPLLLPPPPPLLLLPPLPPPPLLLPLLPLLPPPPPLLPLLLPPLPPPLPPLLPPLPPPLPPPPPPLLPPLLPLPPPLPLLLLPPPPPLLPLPPLPPPLLLPLPPLLLLPLLPPPPPLPPPLLPPPLLLLPLLPPPPPPPPPPLLLLPLPLLLLLPLPPLLLPLPLLLLPPPLPLLPPPLPPLLLPPPLLLPPLLLPPLLPLPLPPLLPPLLPPPPLLLPLPPPLPL...

output:


result:


Subtask #9:

score: 0
Dangerous Syscalls

Test #56:

score: 0
Dangerous Syscalls

input:

600
LPLPPPLLLPPLLPLPLLLLPLLLLLLLLPLLLPLPLPPLPLPLPLPLLLLLPLPPLPLLPLLLLLLPLPLPLPPLPPPLLPLPPPLLPPPLPPLPLLLPPPPPPLPPPPPLLPPPPPLLPPLPLPLPLLLLPPPPPLPLPPLPPPLPPLPPPPLLPPPPLPPLPPLLLLLPPLPPLPLLLLLLLLLPLLLPLPLLLLLLPLLPLLLPPPPPPPLLPLLLPPLLPPPPLPLPLPPLLPLPLPLLLPLPLLLPLLLPLPPPPPPPLLLPPLLPPPLPLPPLLLLLPPLPLPPPLPPL...

output:


result:


Subtask #10:

score: 0
Dangerous Syscalls

Test #58:

score: 0
Dangerous Syscalls

input:

600
PLLLLLLLPPLPLPLPPPPLPPPPLPPPPLPPLLPPLPPLLLPLPPLLLLPPPPPLPLLPLPPLLPPPLLLPLLLLLLLLLLPLPLLPLLPPLLLPLPPLLLLLLPPPLLLLPLLPLLPLLPLPPLPPLPPLLLPLPLPLLPLPLLPLLLLLLLLLLLLPLLLPLPPPLPLLLPLPPLPLLPPLLLPPLPLPPLPPPPLPPLPLLPPLPLLLPPLPLPLPLLPLLLPLLLPLPLPPLLPLPLPPPLPLLPPLLPPLLLPLPLPPLPLLPLLLLLLPPLPPLPLLPLPLPPPLPLLP...

output:


result: