Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) D. Something with XOR Queries
地址:http://codeforces.com/contest/872/problem/D
题目:
2 seconds
256 megabytes
standard input
standard output
This is an interactive problem.
Jury has hidden a permutation p of integers from 0 to n - 1. You know only the length n. Remind that in permutation all integers are distinct.
Let b be the inverse permutation for p, i.e. pbi = i for all i. The only thing you can do is to ask xor of elements pi and bj, printing two indices i and j (not necessarily distinct). As a result of the query with indices i and j you'll get the value
, where
denotes the xoroperation. You can find the description of xor operation in notes.
Note that some permutations can remain indistinguishable from the hidden one, even if you make all possible n2 queries. You have to compute the number of permutations indistinguishable from the hidden one, and print one of such permutations, making no more than 2nqueries.
The hidden permutation does not depend on your queries.
The first line contains single integer n (1 ≤ n ≤ 5000) — the length of the hidden permutation. You should read this integer first.
When your program is ready to print the answer, print three lines.
In the first line print "!".
In the second line print single integer answers_cnt — the number of permutations indistinguishable from the hidden one, including the hidden one.
In the third line print n integers p0, p1, ..., pn - 1 (0 ≤ pi < n, all pi should be distinct) — one of the permutations indistinguishable from the hidden one.
Your program should terminate after printing the answer.
To ask about xor of two elements, print a string "? i j", where i and j — are integers from 0 to n - 1 — the index of the permutation element and the index of the inverse permutation element you want to know the xor-sum for. After that print a line break and make flushoperation.
After printing the query your program should read single integer — the value of
.
For a permutation of length n your program should make no more than 2n queries about xor-sum. Note that printing answer doesn't count as a query. Note that you can't ask more than 2n questions. If you ask more than 2n questions or at least one incorrect question, your solution will get "Wrong answer".
If at some moment your program reads -1 as an answer, it should immediately exit (for example, by calling exit(0)). You will get "Wrong answer" in this case, it means that you asked more than 2n questions, or asked an invalid question. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.
Your solution will get "Idleness Limit Exceeded", if you don't print anything or forget to flush the output, including for the final answer .
To flush you can use (just after printing line break):
- fflush(stdout) in C++;
- System.out.flush() in Java;
- stdout.flush() in Python;
- flush(output) in Pascal;
- For other languages see the documentation.
Hacking
For hacking use the following format:
n
p0 p1 ... pn - 1
Contestant programs will not be able to see this input.
思路:
2n次?
不就是让你询问(i,0)和(0,i)吗,i从1到n。
然后枚举第一个数就好了.O(n^2)
ps:一场涨了212,简直不要太爽
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,a[K],b[K],cnt,ans[K],sa[K],sb[K]; int main(void)
{
ans[]=-;
scanf("%d",&n);
for(int i=;i<n;i++)
{
printf("? %d %d\n",i,);
fflush(stdout);
scanf("%d",a+i);
}
for(int i=;i<n;i++)
{
printf("? %d %d\n",,i);
fflush(stdout);
scanf("%d",b+i);
}
for(int i=;i<n;i++)
{
int ff=;
for(int j=;j<n;j++)
sa[j]=i^a[j];
for(int j=;j<n;j++)
sb[j]=sa[]^b[j];
for(int j=;j<n&&ff;j++)
if(sa[sb[j]]!=j)
ff=;
cnt+=ff;
if(ans[]==-&&ff)
{
for(int j=;j<n;j++)
ans[j]=sa[j];
}
}
printf("!\n%d\n",cnt);
for(int i=;i<n;i++)
printf("%d ",ans[i]);
fflush(stdout);
return ;
}
Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) D. Something with XOR Queries的更多相关文章
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...
- Codeforces Round #440 (Div. 1, based on Technocup 2018 Elimination Round 2) C - Points, Lines and Ready-made Titles
C - Points, Lines and Ready-made Titles 把行列看成是图上的点, 一个点(x, y)就相当于x行 向 y列建立一条边, 我们能得出如果一个联通块是一棵树方案数是2 ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) C. Maximum splitting
地址: 题目: C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input ...
- ACM-ICPC (10/15) Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers You are given two lists of non-zero digits. Let's call an integer pret ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】
C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861B Which floor?【枚举,暴力】
B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861A k-rounding【暴力】
A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)
A. k-rounding 题目意思:给两个数n和m,现在让你输出一个数ans,ans是n倍数且末尾要有m个0; 题目思路:我们知道一个数末尾0的个数和其质因数中2的数量和5的数量的最小值有关系,所以 ...
- 【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration
题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命 ...
随机推荐
- Java环境变量配置错误
1,由于Java的环境变量配置错误,导致用到Java的编译过程中出现错误: 改正办法: wget http://download.oracle.com/otn-pub/java/jdk/8u181-b ...
- jenkins - svn: E170001报错的原因以及解决方案
1. 什么问题What? 使用Jenkins配置的svn拉取项目,Jenkins报错:svn: E170001; Your credentials to connect to the reposito ...
- 【CF618G】Combining Slimes 概率+矩阵乘法
[CF618G]Combining Slimes 题意:一个长度为$1\times n$的网格,每次从最右侧往里推入一个数字1或2(数字会一直跑到最左边的空格子里),加入1的概率为p,2的概率为1-p ...
- php中属性和方法的修饰符
<?php class A{ private function do1(){ echo "do1 called"; } protected function do2(){ e ...
- undefined类型
undefined类型 只有一个特殊的值 undefined 在使用var声明变量但未对其加以初始化,这个变量的值就是undefined 值是undefined的情况: 1.显示声明并初始化变量值 ...
- 关于*** WARNING L15: MULTIPLE CALL TO SEGMENT
编写51程序的时候,有时候会在主函数和中断函数里面调用同一个函数,如果正的出现这种情况,编译器会提出 这种警告: *** WARNING L15: MULTIPLE CALL TO SEGMENT(重 ...
- TFS二次开发07——锁定(Lock)和解锁(UnLock)
一:锁定(Lock) string tpcURL = "http://192.168.83.62:8080/"; TfsTeamProjectCollection tpc = ne ...
- python数据结构之动态数组
数组列表:动态数组(Array List) 简介: 最基础简单的数据结构.最大的优点就是支持随机访问(O(1)),但是增加和删除操作效率就低一些(平均时间复杂度O(n)) 动态数组也称数组列表,在py ...
- create view in view
CREATE VIEW view_region2role AS ( SELECT region_set_id, region_set_name, GROUP_CONCAT(id) gc_id, GRO ...
- JS "trycatch工厂模式"
大家都用过Ajax的异步交互,下面的代码中使用 "trycatch工厂模式" 来进行针对Ajax请求对象的变化点进行封装 <script type="text/ ...