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 ...
随机推荐
- Memcache的客户端连接系列(四) PHP
关键词: Memcached PHP 客户端 声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(Memcached)的用户指南.客户端连接方法通用,故摘抄过来分享给大家. PHP客户端 Re ...
- halcon安装提示could not write updated path to HKLM
halcon安装提示could not write updated path to HKLM 我们在安装Halcon软件时,会弹出如上图错误信息,这个错误信息提示软件无法写入本地注册表,造成这个原因有 ...
- ThinkPHP - 3 - IDE选择以及Eclipse PDT打开ThinkPHP项目
ThinkPHP框架已部署到SAE(新浪云),且代码已获取到本地.眼前面临的问题就是,对ThinkPHP项目选择哪种开发工具(IDE)? 经过简单的查找比较,以及电脑里已装有Eclipse的因素,遂决 ...
- MongoDB3.2 集群搭建
一.集群的理论知识 1.1 集群成员 MongoDB的集群类似于GreenPlum集群,由一个入口节点负责任务分发与结果统计,分片结节负责执行任务.不同GP,多了一个config servers. 集 ...
- Linux查看物理CPU个数,核数,逻辑CPU个数;内存信息
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...
- HDU 1569 方格取数(2)(最大流最小割の最大权独立集)
Description 给你一个m*n的格子的棋盘,每个格子里面有一个非负数. 从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取数所在的2个格子不能相邻,并且取出的数的和最大. ...
- 自测之Lesson11:消息和消息队列
题目:key及ftok函数的作用. 解答: key是用来创建消息队列的一个参数,当两个key相同时,创建消息队列会引起“误会”(除非有意为之).所以我们可以通过ftok函数来获得一个“不易重复”的ke ...
- SFTP服务器之创建普通用户
这篇博客主要写以下几点: 1.介绍SFTP服务器 2.用SFTP服务器的root用户a创建普通用户 3.修改普通用户名称以及默认登入时的目录名称 4.创建普通用户踩过的坑以及收获 一.介绍SFTP服务 ...
- LintCode-212.空格替换
空格替换 设计一种方法,将一个字符串中的所有空格替换成 %20 .你可以假设该字符串有足够的空间来加入新的字符,且你得到的是"真实的"字符长度. 你的程序还需要返回被替换后的字符串 ...
- Swift-枚举enum理解
//定义一个枚举 //枚举的语法,enum开头,每一行成员的定义使用case关键字开头,一行可以定义多个关键字 enum CompassPoint { case North case South ca ...