/ Randle /

记录详情

Memory Exceeded


  
# 状态 耗时 内存占用
#1 Accepted 3ms 2.215 MiB
#2 Accepted 6ms 2.352 MiB
#3 Accepted 5ms 2.332 MiB
#4 Wrong Answer 5ms 2.125 MiB
#5 Wrong Answer 22ms 9.75 MiB
#6 Wrong Answer 17ms 9.875 MiB
#7 Wrong Answer 40ms 2.625 MiB
#8 Memory Exceeded ≥1003ms ≥256.0 MiB
#9 Wrong Answer 625ms 230.098 MiB
#10 Memory Exceeded ≥1006ms ≥256.0 MiB

代码

#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 5e4+5;
int c[maxn];
int len;
inline int lowbit(int x){return x&-x;}
inline void inc(int x){while(x<=len){c[x]++;x+=lowbit(x);}}
inline int sum(int x){int ret  = 0;while(x){ret+=c[x];x-=lowbit(x);}return ret;}
struct str {
	string s;
	int index;
} arr[maxn];
int newa[maxn];
inline bool operator<(const str &s1,const str &s2){
	return s1.s<s2.s;
}
int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	string s;
	cin>>s;
	len = n;
	for(int i = 0; i<n; i++) {
		arr[i+1].s = s.substr(i,m);
		arr[i+1].index = i+1;
	}
	sort(arr+1,arr+1+len);
	for(int i = 1;i<=len;i++){
		int val;
		if(arr[i].s!=arr[i-1].s){
			val  = i;
		}else{
			val = newa[arr[i-1].index];
		}
		arr[i].s.clear();
		arr[i].s.shrink_to_fit(); 
		newa[arr[i].index] = val;
	}
	long long ans = 0;
	for(int i = 1;i<=len;i++){
		inc(newa[i]);
		ans+=i-sum(newa[i]);
	}
	cout<<ans;
	return 0;
}

信息

递交者
类型
递交
题目
后缀数组
题目数据
下载
语言
C++
递交时间
2017-11-06 20:41:19
评测时间
2017-11-06 20:41:57
评测机
分数
30
总耗时
≥2737ms
峰值内存
≥256.0 MiB