CodeForces 731D 80-th Level Archeology
区间并。
对于上下两个数字,如果不一样,那么可以计算出哪一段范围内可以保证字典序,并且后面所有位置都无需再考虑。对所有范围求交集就是答案了。
求交集写起来有点烦,直接对不可取的范围求并即可。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c))
{
x = x * + c - '';
c = getchar();
}
} vector<int>v[];
int n,c,L,R,len[],ans[]; bool check(int a,int b)
{
if(v[a].size()<=v[b].size()) return ;
for(int j=;j<v[b].size();j++) if(v[a][j]!=v[b][j]) return ;
return ;
} int main()
{
scanf("%d%d",&n,&c);
for(int i=;i<n;i++)
{
scanf("%d",&len[i]);
for(int j=;j<len[i];j++)
{
int x; scanf("%d",&x);
v[i].push_back(x);
}
} for(int i=;i<n;i++)
{
for(int j=;j<len[i];j++)
{
if(v[i-].size()-<j) break;
if(v[i-][j]!=v[i][j])
{
if(v[i-][j]>v[i][j])
{
ans[]++;
ans[c-v[i-][j]+]--; ans[c-v[i][j]+]++;
ans[c]--;
}
else
{
ans[c-v[i][j]+]++;
ans[c-v[i-][j]+]--;
}
break;
}
} } for(int i=;i<=c;i++) ans[i]=ans[i]+ans[i-]; int fail=; int q;
for(int i=;i<=c-;i++) if(ans[i]==) q=i,fail=; for(int i=;i<n;i++)
{
if(check(i-,i))
{
fail=; break;
}
} if(fail==) printf("-1\n");
else printf("%d\n",q); return ;
}
CodeForces 731D 80-th Level Archeology的更多相关文章
- 【codeforces 731D】80-th Level Archeology
[题目链接]:http://codeforces.com/contest/731/problem/D [题意] 给你n个象形文; 每个象形文由l[i]个数字组成; 你可以把所有的组成象形文的数字同时增 ...
- Codeforces Round #376 (Div. 2) D. 80-th Level Archeology —— 差分法 + 线段扫描法
题目链接:http://codeforces.com/contest/731/problem/D D. 80-th Level Archeology time limit per test 2 sec ...
- 80-th Level Archeology
80-th Level Archeology time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Educational Codeforces Round 80 (Rated for Div. 2)
A. Deadline 题目链接:https://codeforces.com/contest/1288/problem/A 题意: 给你一个 N 和 D,问是否存在一个 X , 使得 $x+\lce ...
- Educational Codeforces Round 80 A-E简要题解
contest链接:https://codeforces.com/contest/1288 A. Deadline 题意:略 思路:根据题意 x + [d/(x+1)] 需要找到一个x使得上式小于等于 ...
- Educational Codeforces Round 80 (Rated for Div. 2)D E
D枚举子集 题:https://codeforces.com/contest/1288/problem/D题意:给定n个序列,每个序列m个数,求第i个和第j个序列组成b序列,b序列=max(a[i][ ...
- Codeforces Round #80 Div.1 D
思路:考虑离线操作,以y为关键字排序,对于y相同的一起操作,然后考虑y的范围,当y<=sqrt(n)时,直接O(n)预处理出f[x]表示f[x]+f[x+y]+f[x+2*y]+..+f[x+k ...
- Codeforces 731D Funny Game
Description Once upon a time Petya and Gena gathered after another programming competition and decid ...
- Codeforces731D 80-th Level Archeology
考虑将两个单词变成有序,我们可以得到一个或者两个旋转次数的区间. 然后考虑将两组单词变成有序,比如[l,mid]和[mid+1,r],对于mid和mid+1这两个单词我们可以求出使他们有序的旋转次数的 ...
随机推荐
- table第一行合并,其余行宽度失效问题
<col>标签 http://www.w3school.com.cn/tags/tag_col.asp 由于表格中有一行合并过,所以其它没有合并的行的列宽就会平均化,对列宽的设置也会失效. ...
- mysql 并发下数据不一致的问题分析及解决
MySQL 5.6 , InnoDB存储引擎,默认事务隔离级别(REPEATABLE-READ) 初始sql 脚本如下: CREATE DEFINER=`root`@`localhost` PROCE ...
- 【BZOJ1221】【HNOI2001】软件开发 [费用流]
软件开发 Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 某软件公司正在规划一项n天的软件开 ...
- 【Luogu】P3930 SAC E#1 - 一道大水题 Knight
[题目]洛谷10月月赛R1 提高组 [题意]给定n*n棋盘和<=16个棋子,给几个棋子种类和攻击范围,现我方只有一马,求能否吃王. [算法]状压+BFS [题解]16种棋子中,马不能吃马,直接处 ...
- 【CodeForces】835D Palindromic characteristics
[题意]给你一个串,让你求出k阶回文子串有多少个.k从1到n.k阶子串的定义是:子串本身是回文串,而且它的左半部分也是回文串. [算法]区间DP [题解]涉及回文问题的区间DP都可以用类似的写法,就是 ...
- 如何用CMD开启3389与查看3389端口
开启 REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections / ...
- 【Python项目】使用Face++的人脸识别detect API进行本地图片情绪识别并存入excel
准备工作 首先,需要在Face++的主页注册一个账号,在控制台去获取API Key和API Secret. 然后在本地文件夹准备好要进行情绪识别的图片/相片. 代码 介绍下所使用的第三方库 ——url ...
- Linux 入门记录:十三、Linux 扩展权限
一.默认权限 每一个终端都有一个 umask 属性,是用来确定新建文件或目录的默认权限的“掩码”(mask 有“掩码”的含义,至于 u,后面说). Linux 中一般有默认的权限掩码,使用命令 uma ...
- 【Android XML】Android XML 转 Java Code 系列之 Selector(2)
今天我们要把drawable下的selector的XML文件转换成Java代码.(打包进jar,不依赖apk) 在转换工具中的代码为: https://github.com/SickWorm/Andr ...
- Python Matplotlib图表汉字显示成框框的解决办法
http://blog.sina.com.cn/s/blog_662dcb820102vu3d.html http://blog.csdn.net/fyuanfena/article/details/ ...