0
点赞
收藏
分享

微信扫一扫

AtCoder Regular Contest 071


C - 怪文書 / Dubious Document

Time Limit: 2 sec / Memory Limit: 256 MB

Score : 300300 points

Problem Statement

Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.

He will receive a headline which contains one of the strings S1,...,SnS1,...,Sn tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.

Find the longest string that can be created regardless of which string among S1,...,SnS1,...,Sn the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.

Constraints

  • 1≤n≤501≤n≤50
  • 1≤|Si|≤501≤|Si|≤50 for every i=1,...,ni=1,...,n.
  • SiSi consists of lowercase English letters (​​a​​​ - ​​z​​) for every i=1,...,ni=1,...,n.

Input

Input is given from Standard Input in the following format:


nn S1S1 ...... SnSn


Output

Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line.

Sample Input 1 Copy

Copy


3 cbaa daacc acacac


Sample Output 1 Copy

Copy


aac


The strings that can be created from each of ​​cbaa​​​, ​​daacc​​​ and ​​acacac​​​, are ​​aa​​​, ​​aac​​​, ​​aca​​​, ​​caa​​​ and so forth. Among them, ​​aac​​​, ​​aca​​​ and ​​caa​​​ are the longest, and the lexicographically smallest of these three is ​​aac​​.

Sample Input 2 Copy

Copy


3 a aa b


Sample Output 2 Copy

Copy


 


The answer is an empty string.

无序字符串+字典序大大降低了难度

#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int a[N];
int n,k;
int vis[30],ans_vis[30];
int main()
{
int n;
scanf("%d",&n);
memset(ans_vis,127,sizeof(ans_vis));
for(int i=1;i<=n;i++)
{
string s;
cin>>s;
memset(vis,0,sizeof(vis));
for(int j=0;j<s.size();j++)
{
vis[s[j]-'a']++;
}
for(int j=0;j<26;j++)
{
//cout<<vis[i]<<endl;
ans_vis[j]=min(ans_vis[j],vis[j]);
}
}
for(int i=0;i<26;i++)
{
for(int j=0;j<ans_vis[i];j++)
{
cout<<(char)('a'+i);
}
}
return 0;
}

D - 井井井 / ###

Time Limit: 2 sec / Memory Limit: 256 MB

Score : 500500 points

Problem Statement

On a two-dimensional plane, there are mm lines drawn parallel to the xx axis, and nn lines drawn parallel to the yy axis. Among the lines parallel to the xx axis, the ii-th from the bottom is represented by y=yiy=yi. Similarly, among the lines parallel to the yy axis, the ii-th from the left is represented by x=xix=xi.

For every rectangle that is formed by these lines, find its area, and print the total area modulo 109+7109+7.

That is, for every quadruple (i,j,k,l)(i,j,k,l) satisfying 1≤i<j≤n1≤i<j≤n and 1≤k<l≤m1≤k<l≤m, find the area of the rectangle formed by the lines x=xix=xi, x=xjx=xj, y=yky=yk and y=yly=yl, and print the sum of these areas modulo 109+7109+7.

Constraints

  • 2≤n,m≤1052≤n,m≤105
  • −109≤x1<...<xn≤109−109≤x1<...<xn≤109
  • −109≤y1<...<ym≤109−109≤y1<...<ym≤109
  • xixi and yiyi are integers.

Input

Input is given from Standard Input in the following format:


nn mm x1x1 x2x2 ...... xnxn y1y1 y2y2 ...... ymym


Output

Print the total area of the rectangles, modulo 109+7109+7.

Sample Input 1 Copy

Copy


3 3 1 3 4 1 3 6


Sample Output 1 Copy

Copy


60


The following figure illustrates this input:

AtCoder Regular Contest 071_i++

The total area of the nine rectangles A, B, ..., I shown in the following figure, is 6060.

AtCoder Regular Contest 071_i++_02

Sample Input 2 Copy

Copy


6 5 -790013317 -192321079 95834122 418379342 586260100 802780784 -253230108 193944314 363756450 712662868 735867677


Sample Output 2 Copy

Copy


835067060


题意:

n条x=x[i]的线,m条y=y[i]的线,求所有的线组成的矩形面积之和。

分析:

 

正解:

以前做过一个类似的

AtCoder Regular Contest 071_ico_03

O(n^2*m^2)

推出:

AtCoder Regular Contest 071_Memory_04

O(max(n,m)*max(n,m))

 此题的思路

n=3为例

  1        2       3

1 2     2 3    3 4

1 3     2 4  

1 4

1列:3个1 2 ,2个 2 3,1个3 4

2列:               2个 2 3,1个3 4

1列:                               1个3 4

       1*3             2*(3-1)     3*1

 

AtCoder Regular Contest 071_Memory_05

O(nlogn)或O(mlogm)

正解:计算xk的贡献 xk加了k-1次 被减了n-k次 s

AtCoder Regular Contest 071_i++_06

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
const int MOD=1e9+7;
ll x[N],y[N];
int n,m;
int main()
{
int n;
scanf("%d%d",&n,&m);
int maxX=-(1e9+7),minX=1e9+7;
int maxY=-(1e9+7),minY=1e9+7;
for(int i=1;i<=n;i++)
{
scanf("%lld",&x[i]);
}

for(int i=1;i<=m;i++)
{
scanf("%lld",&y[i]);
}
sort(x+1,x+n+1);
sort(y+1,y+m+1);
ll ans1=0,ans2=0;;
for(int i=1;i<n;i++)
{
ans1=(ans1%MOD+(((x[i+1]-x[i])%MOD*i%MOD*(n-i)%MOD)%MOD)%MOD)%MOD;

}
for(int i=1;i<m;i++)
{
ans2=(ans2%MOD+((y[i+1]-y[i])%MOD*i%MOD*(m-i)%MOD)%MOD)%MOD;
}

cout<<(ans1%MOD*ans2%MOD)%MOD<<endl;
return 0;
}

 

举报

相关推荐

0 条评论