Position:http://codeforces.com/contest/721

我的情况

开始还是rank1,秒出C。(11:00机房都走光了,我ma到11:05才走,只打了一个小时)

结果。。。

FST!!尤其是第一题还WA了一发。gi烂。B题还ma得慢。

最后滚到青名。。。。。

反思

首先每次都WA了A题,很不应该,虽然快,样例都没测就交,结果丢了50分。

B题ma得慢。

C题未考虑到LL情况,虽然有上界T,但我没用啊,直接记录到这个点的用了几个点的最短距离,dfs时没有判断与T的关系。统计答案才判,结果FST,WA烂,掉raiting。

D不能怪没时间。很水但没做?问题,人家一个小时也可以AK。我觉得还是分析问题能力要提升,ma代码速度提高,细节要考虑清楚。

官方题解

Round374


A. One-dimensional Japanese Crossword

time limit per test

1 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia https://en.wikipedia.org/wiki/Japanese_crossword).

Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of n squares (e.g. japanese crossword sized 1 × n), which he wants to encrypt in the same way as in japanese crossword.

The example of encrypting of a single row of japanese crossword.

Help Adaltik find the numbers encrypting the row he drew.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the length of the row. The second line of the input contains a single string consisting of n characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).

Output

The first line should contain a single integer k — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.

The second line should contain k integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.

 
input
3
BBW
output
1
2
input
13
WBBBBWWBWBBBW
output
3
4 1 3
Note

The last sample case correspond to the picture in the statement.

Understanding

求一个字符串中连续一段B出现的个数,并输出每段的数目

Solution

模拟?枚举→CF官方implementation(翻译:贯彻实施扫一遍→运用吧)。O(n)将字符串扫一遍,如果发现一个'B',往后找'B',记录个数即可

Introspection

A题wa了一发,50分啊,raiting啊。

以后一定要测样例,并且考虑到各种特殊的情况,n=1,极限数据爆LL

下次拿小号开黑。。。只要不skip就行。

Code

// <A.cpp> - Fri Sep 30 22:03:52 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long LL;
const int MAXN=;
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
char s[MAXN];int a[MAXN];
int main()
{
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
int n=gi(),k=;
scanf("%s",s);
for(int i=;i<n;i++)
if(s[i]=='B'){
int j=i;k++;
while(s[j++]=='B')a[k]++;
i=j-;
}
printf("%d\n",k);
for(int i=;i<=k;i++)printf("%d ",a[i]);
return ;
}

B. Passwords

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.

Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.

Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.

Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).

Input

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds.

The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters.

The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.

Output

Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.

 
input
5 2
cba
abc
bb1
abC
ABC
abc
output
1 15
input
4 100
11
22
1
2
22
output
3 4
Note

Consider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.

Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.

Understanding

给你很多个输入的密码,并且给你正确的密码(保证输入的中有正确的密码)。求输入顺序使得最少与最多的此时可以得到密码,要求按字符串长度顺序输出。

Solution

贪心。记每个字符串的长度,sort。最小:把长度小的输完,然后再输出+1就行。最大:长度小的输完+长度相等并且不等于密码串的个数+1。

Code

// <B.cpp> - Fri Sep 30 22:03:53 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=;
const int MAXM=;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
char c[MAXN];
struct node{
char s[MAXN];int l;
bool operator<(node b)const{return l<b.l;}
void read(){scanf("%s",s);l=strlen(s);}
bool pan(){
for(int i=;i<l;i++)
if(s[i]!=c[i])return true;
return false;
}
}a[MAXN];
int main()
{
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
int n=gi(),k=gi();
for(int i=;i<=n;i++)a[i].read();
scanf("%s",c);int i,l=strlen(c),ans=;
sort(a+,a++n);
for(i=;i<=n;i++){
if(a[i].l>=l)break;
ans++;
if(i%k==)ans+=;
}
printf("%d ",ans+);int kk=(i-)%k;
for(;i<=n;i++){
if(a[i].l>l)break;
if(a[i].pan()){
ans++;kk++;if(kk%k==)ans+=;
}
}
printf("%d",ans+);
return ;
}

C. Journey

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently Irina arrived to one of the most famous cities of Berland — the Berlatov city. There are n showplaces in the city, numbered from 1 to n, and some of them are connected by one-directional roads. The roads in Berlatov are designed in a way such that there are no cyclic routes between showplaces.

Initially Irina stands at the showplace 1, and the endpoint of her journey is the showplace n. Naturally, Irina wants to visit as much showplaces as she can during her journey. However, Irina's stay in Berlatov is limited and she can't be there for more than T time units.

Help Irina determine how many showplaces she may visit during her journey from showplace 1 to showplace n within a time not exceeding T. It is guaranteed that there is at least one route from showplace 1 to showplace n such that Irina will spend no more than T time units passing it.

Input

The first line of the input contains three integers n, m and T (2 ≤ n ≤ 5000,  1 ≤ m ≤ 5000,  1 ≤ T ≤ 109) — the number of showplaces, the number of roads between them and the time of Irina's stay in Berlatov respectively.

The next m lines describes roads in Berlatov. i-th of them contains 3 integers ui, vi, ti (1 ≤ ui, vi ≤ n, ui ≠ vi, 1 ≤ ti ≤ 109), meaning that there is a road starting from showplace ui and leading to showplace vi, and Irina spends ti time units to pass it. It is guaranteed that the roads do not form cyclic routes.

It is guaranteed, that there is at most one road between each pair of showplaces.

Output

Print the single integer k (2 ≤ k ≤ n) — the maximum number of showplaces that Irina can visit during her journey from showplace 1 to showplace n within time not exceeding T, in the first line.

Print k distinct integers in the second line — indices of showplaces that Irina will visit on her route, in the order of encountering them.

If there are multiple answers, print any of them.

 
input
4 3 13
1 2 5
2 3 7
2 4 8
output
3
1 2 4
input
6 6 7
1 2 2
1 3 3
3 6 3
2 4 2
4 6 2
6 5 1
output
4
1 2 4 6

Understanding

给你一个DAG(有向无环图),求1~n路径中,走过点数最多,且边权和<=T的方案。

Solution

记忆化搜索,f[i][j]记录,第i个点走到n号点经过j的最小边权和。转移:f[i][j]=min{f[son][j-1]+w[edge]}

每次转移用d[i][j]记录它转到的儿子。

Code

// <C.cpp> - Fri Sep 30 22:03:53 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
const int MAXN=;
const int MAXM=MAXN<<;
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
int n,tot,be,T;
int to[MAXM],ne[MAXM],fr[MAXN],W[MAXM];
int f[MAXN][MAXN],d[MAXN][MAXN];bool used[MAXN];
void add(int u,int v,int w){
to[++tot]=v;ne[tot]=fr[u];fr[u]=tot;W[tot]=w;
}
void dfs(int x){
if(x==n){f[x][]=;return;}
if(used[x])return;used[x]=true;
for(int i=fr[x];i;i=ne[i]){
dfs(to[i]);
for(int j=;j<=n;j++){
if(f[to[i]][j-]==be)continue;
if(f[to[i]][j-]+W[i]>T)continue;//..会爆int
if(f[to[i]][j-]+W[i]<f[x][j]){
f[x][j]=f[to[i]][j-]+W[i];
d[x][j]=to[i];
}
}
}
}
int main()
{
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
n=gi();int m=gi();T=gi();
for(int i=;i<=m;i++){
int u=gi(),v=gi(),w=gi();
add(u,v,w);
}
memset(f,,sizeof(f));be=f[][];
dfs();int i;
for(i=n;i;i--)
if(f[][i]<=T)break;
printf("%d\n",i);
for(int o=;i;i--){
printf("%d ",o);
o=d[o][i];
}
return ;
}

D. Maxim and Array

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or subtract it from arbitrary array elements. Formally, by applying single operation Maxim chooses integer i (1 ≤ i ≤ n) and replaces the i-th element of array ai either with ai + x or with ai - x. Please note that the operation may be applied more than once to the same position.

Maxim is a curious minimalis, thus he wants to know what is the minimum value that the product of all array elements (i.e. ) can reach, if Maxim would apply no more than k operations to it. Please help him in that.

Input

The first line of the input contains three integers n, k and x (1 ≤ n, k ≤ 200 000, 1 ≤ x ≤ 109) — the number of elements in the array, the maximum number of operations and the number invented by Maxim, respectively.

The second line contains n integers a1, a2, ..., an () — the elements of the array found by Maxim.

Output

Print n integers b1, b2, ..., bn in the only line — the array elements after applying no more than k operations to the array. In particular, should stay true for every 1 ≤ i ≤ n, but the product of all array elements should be minimum possible.

If there are multiple answers, print any of them.

 
input
5 3 1
5 4 3 5 2
output
5 4 3 5 -1
input
5 3 1
5 4 4 5 5
output
5 1 4 5 5

Understanding

给你一列数和k个操作,每次操作要将一个数(+|-)x,舍得最后乘积最小。

Solution

贪心。%遥犇。首先可以想到,使结果为负会很好,如果为正,也要使其尽量小。那么记录为负的个数,开小根堆记录绝对值的最小值,每次修改最小值会是答案更小。

设a×b,a<b,(a+x)×b<a×(b+x),即证。如果剩下负数为奇数个,+x else -x。

Code

// <D.cpp> - Fri Sep 30 22:03:53 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <queue>
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
const int MAXN=;
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
LL a[MAXN];
struct node{LL s;int p;};
priority_queue<node>q;
IN bool operator<(RG node a,RG node b){return a.s>b.s;}
int main()
{
freopen("D.in","r",stdin);
freopen("D.out","w",stdout);
int n=gi(),k=gi(),x=gi(),b=;
for(int i=;i<=n;i++)
a[i]=gi(),q.push((node){a[i]<?-a[i]:a[i],i}),b+=a[i]<;
while(k--){
int p=q.top().p;q.pop();b-=a[p]<;
if(b&)a[p]+=x;else a[p]-=x;
b+=a[p]<;q.push((node){a[p]<?-a[p]:a[p],p});
}
for(int i=;i<=n;i++)printf("%lld ",a[i]);
return ;
}

【Codeforces】 Round #374 (Div. 2)的更多相关文章

  1. 【Codeforces】Round #491 (Div. 2) 总结

    [Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...

  2. 【Codeforces】Round #488 (Div. 2) 总结

    [Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...

  3. 【Codeforces】Round #376 (Div. 2)

    http://codeforces.com/contest/731 不发题面了,自己点链接 总结一下 考场上 原以为这次要加很多raiting... 但FST狗记邓,只加了58rating 总结一下 ...

  4. 【Codeforces】Round #375 (Div. 2)

    Position:http://codeforces.com/contest/723 我的情况 啊哈哈,这次raiting肯定要涨,接受过上次的教训,先用小号送肉,大号都是一发切,重回蓝咯 结果... ...

  5. 【Codeforces】Round #460 E - Congruence Equation 中国剩余定理+数论

    题意 求满足$na^n\equiv b \pmod p$的$n$的个数 因为$n \mod p ​$循环节为$p​$,$a^n\mod p​$循环节为$p-1​$,所以$na^n \mod p​$循环 ...

  6. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  7. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  8. 【CF981F】Round Marriage(二分答案,二分图匹配,Hall定理)

    [CF981F]Round Marriage(二分答案,二分图匹配,Hall定理) 题面 CF 洛谷 题解 很明显需要二分. 二分之后考虑如果判定是否存在完备匹配,考虑\(Hall\)定理. 那么如果 ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

随机推荐

  1. Mybatis与Spring整合方法

    实现mybatis与spring进行整合,通过spring管理SqlSessionFactory.mapper接口. tips:mybatis官方提供与mybatis与spring整合jar包. 一. ...

  2. 01Hypertext Preprocessor

    Hypertext Preprocessor PHP即Hypertext Preprocessor是一种被广泛使用的开放源代码多用途动态交互性站点的强有力的服务器端脚本语言尤其适用于 Web开发人员可 ...

  3. 配置redis三主三从

    主从环境 centos7.6 redis4.0.1 主 从 192.168.181.139:6379 192.168.181.136:6379 192.168.181.136:6380 192.168 ...

  4. 网络编程 - socket接收大数据

    通过socket,实现客户端发送命令,将服务端执行出的结果,反回到客户端,主要4个步骤:1.服务端返回数据: 2.服务端返回数据的大小: 3.客户端接收返回数据的大小: 4.客户端按返回数据大小接收数 ...

  5. 爬虫之Requests库

    官方文档:http://cn.python-requests.org/zh_CN/latest/ 一.引子 import requests resp = requests.get("http ...

  6. 51NOD 1287 加农炮(不水的线段树)

    >>点击进入原题测试<< Input示例 Output示例 思路:刚开始以为结点存最大值就行了,然后大于左子树的最大值就能进入右子树:然后发现样例都过不了:后面发现,并不是这个 ...

  7. 这个函数有搞头,要调试通过就差不多啦--ImpersonateActiveUserAndRun

    //Function to run a process as active user from windows service void ImpersonateActiveUserAndRun() { ...

  8. A Simple Problem with Integers 线段树 区间更新 区间查询

    Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 115624   Accepted: 35897 Case Time Lim ...

  9. J - A Bug's Life 并查集

    Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...

  10. SVN提交时报错:Commit blocked by pre-commit hook (exit code 1) with no output.

    可能的原因: 提交代码的SVN命令中,Comment长度短了.参考:http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-howto-minl ...