Codeforces Round #332 (Div. 2)B. Spongebob and Joke
2 seconds
256 megabytes
standard input
standard output
While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. The naughty Sponge browsed through Patrick's personal stuff and found a sequence a1, a2, ..., am of length m, consisting of integers from 1 to n, not necessarily distinct. Then he picked some sequence f1, f2, ..., fn of length n and for each number ai got number bi = fai. To finish the prank he erased the initial sequence ai.
It's hard to express how sad Patrick was when he returned home from shopping! We will just say that Spongebob immediately got really sorry about what he has done and he is now trying to restore the original sequence. Help him do this or determine that this is impossible.
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the lengths of sequences fi and bi respectively.
The second line contains n integers, determining sequence f1, f2, ..., fn (1 ≤ fi ≤ n).
The last line contains m integers, determining sequence b1, b2, ..., bm (1 ≤ bi ≤ n).
Print "Possible" if there is exactly one sequence ai, such that bi = fai for all i from 1 to m. Then print m integers a1, a2, ..., am.
If there are multiple suitable sequences ai, print "Ambiguity".
If Spongebob has made a mistake in his calculations and no suitable sequence ai exists, print "Impossible".
3 3
3 2 1
1 2 3
Possible
3 2 1
3 3
1 1 1
1 1 1
Ambiguity
3 3
1 2 1
3 3 3
Impossible
In the first sample 3 is replaced by 1 and vice versa, while 2 never changes. The answer exists and is unique.
In the second sample all numbers are replaced by 1, so it is impossible to unambiguously restore the original sequence.
In the third sample fi ≠ 3 for all i, so no sequence ai transforms into such bi and we can say for sure that Spongebob has made a mistake.
打了好几8次cf了 一直掉到灰名 昨天终于上分了 绿了 关键的一题(纪念翻墙半夜三更打cf的日子)
题意: 输入 n,m
第二行 n个整数 f1, f2, ..., fn (1 ≤ fi ≤ n).
第三行 m个整数 b1, b2, ..., bm (1 ≤ bi ≤ n).
判断 有且只有一个bi = fai 输出 fai的位置;
当b 没有在 f出现时输出 Impossible
当b 在f中出现 但f的位置不唯一时输出Ambiguity
除此之外 输出 Possible 及b1...bm 对应的位置 看懂题意 代码很简单
比赛的时候 被hack了一次
早点睡了 c题要补
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp1;
map<int,int>mp2;
map<int,int>mp3;
int n,m;
int a,b;
int s[100005];
int re[100005];
int main()
{
mp1.clear();
mp2.clear();
mp3.clear();
memset(s,0,sizeof(s));
memset(re,0,sizeof(re));
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d",&a);
mp1[a]++;
mp2[a]=i+1;
}
for(int i=0;i<m;i++)
{
scanf("%d",&s[i]);
mp3[s[i]]=1;
}
for(int i=0;i<m;i++)
{
if(mp2[s[i]]==0)
{
printf("Impossible\n");
return 0;
}
re[i]=mp2[s[i]];
}
for(int i=1;i<=n;i++)
{
if(mp1[i]>=2&&mp3[i])
{
printf("Ambiguity\n");
return 0;
}
}
printf("Possible\n");
printf("%d",re[0]);
for(int i=1;i<m;i++)
printf(" %d",re[i]);
printf("\n");
return 0;
}
Codeforces Round #332 (Div. 2)B. Spongebob and Joke的更多相关文章
- Codeforces Round #332 (Div. 2) B. Spongebob and Joke 水题
B. Spongebob and Joke Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599 ...
- Codeforces Round #332 (Div. 2)_B. Spongebob and Joke
B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #332 (Div. 2) B. Spongebob and Joke 模拟
B. Spongebob and Joke While Patrick was gone shopping, Spongebob decided to play a little trick ...
- Codeforces Round #332 (Div. 二) B. Spongebob and Joke
Description While Patrick was gone shopping, Spongebob decided to play a little trick on his friend. ...
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares 数学题枚举
D. Spongebob and Squares Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares(枚举)
http://codeforces.com/problemset/problem/599/D 题意:给出一个数x,问你有多少个n*m的网格中有x个正方形,输出n和m的值. 思路: 易得公式为:$\su ...
- Codeforces Round #332 (Div. 2)D. Spongebob and Squares 数学
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calcula ...
- Codeforces Round #332 (Div. 2)
水 A - Patrick and Shopping #include <bits/stdc++.h> using namespace std; int main(void) { int ...
- Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树
C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...
随机推荐
- Siki_Unity_2-1_API常用方法和类详细讲解(上)
Unity 2-1 API常用方法和类详细讲解(上) 任务1&2:课程前言.学习方法 && 开发环境.查API文档 API: Application Programming I ...
- 《Git学习指南》学习笔记(一)
第二章 入门 git的安装 在Linux下,git的安装很简单.以我的系统Deepin/Ubuntu为例,只需在终端敲入sudo apt-get install git即可.其他Linux发行版可尝试 ...
- CSP201612-1:中间数
引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...
- (转)GEM -次表面散射的实时近似
次表面散射(Subsurface Scattering),简称SSS,或3S,是光射入非金属材质后在内部发生散射, 最后射出物体并进入视野中产生的现象, 即光从表面进入物体经过内部散射,然后又通过物体 ...
- ActiveMQ服务器之间传输对象,项目A发送对象到项目B接收发送对象《二》
ActiveMQ服务器之间传输对象,项目A发送对象到项目B接收发送对象<一> 上一篇文章写到对象之间传输使用线程方式 ,无法使用监听方式,最近解决了使用监听方式接收对象,本次使用配置文件方 ...
- vista x64 vs2010 win32添加资源 未能完成操作解决办法
非常痛苦的感觉,不能用vc6,msdn library也不好用,去2k3系统试了下,没有任何问题,无奈想重装系统了,但是太浪费时间,装了虚拟机也是vistax64的,安装之后正常... 卸载重新安装依 ...
- 【主席树维护mex】 【SG函数递推】 Problem H. Cups and Beans 2017.8.11
Problem H. Cups and Beans 2017.8.11 原题: There are N cups numbered 0 through N − 1. For each i(1 ≤ i ...
- 对int类型最小值INT_MIN取负值结果不变
在32位系统中,int类型的最大值是0x7fffffff(即除了最高的1Bit其他31位都为1),而最小值是0x80000000(除了最高1bit,其他31位都为0). 显然,对于最小值求负数是不存在 ...
- ffmpeg实现mjpeg摄像头的采集-预览-拍照
摄像头输出是mjpeg格式的,需要实现在线预览功能,然后实现拍照功能 1.可以设置采集图像的分辨率,预览分辨率为640*480,可以自定义 2.ctrl+\ 拍照,ctrl+c 退出 void tes ...
- Struts2中Action各种转发类型
Struts2:Action中result的各种转发类型: 内部请求转发dispatcher(默认值) redirect.redirectAction.plainText1.redirect是重定向到 ...