제출 #794700

#제출 시각아이디문제언어결과실행 시간메모리
794700FEDIKUS앨리스, 밥, 서킷 (APIO23_abc)C++17
8 / 100
54 ms4940 KiB
#include "abc.h" #include<bits/stdc++.h> using namespace std; // you may find the definitions useful const int OP_ZERO = 0; // f(OP_ZERO, x0, x1) = 0 const int OP_NOR = 1; // f(OP_NOR, x0, x1) = !(x0 || x1) const int OP_GREATER = 2; // f(OP_GREATER, x0, x1) = (x0 > x1) const int OP_NOT_X1 = 3; // f(OP_NOT_X1, x0, x1) = !x1 const int OP_LESS = 4; // f(OP_LESS, x0, x1) = (x0 < x1) const int OP_NOT_X0 = 5; // f(OP_NOT_X0, x0, x1) = !x0 const int OP_XOR = 6; // f(OP_XOR, x0, x1) = (x0 ^ x1) const int OP_NAND = 7; // f(OP_NAND, x0, x1) = !(x0 && x1) const int OP_AND = 8; // f(OP_AND, x0, x1) = (x0 && x1) const int OP_EQUAL = 9; // f(OP_EQUAL, x0, x1) = (x0 == x1) const int OP_X0 = 10; // f(OP_X0, x0, x1) = x0 const int OP_GEQ = 11; // f(OP_GEQ, x0, x1) = (x0 >= x1) const int OP_X1 = 12; // f(OP_X1, x0, x1) = x1 const int OP_LEQ = 13; // f(OP_LEQ, x0, x1) = (x0 <= x1) const int OP_OR = 14; // f(OP_OR, x0, x1) = (x0 || x1) const int OP_ONE = 15; // f(OP_ONE, x0, x1) = 1 // Alice int // returns la alice( /* in */ const int n, /* in */ const char names[][5], /* in */ const unsigned short numbers[], /* out */ bool outputs_alice[] ) { vector<string> imena; for(int i=0;i<n;i++) imena.push_back(names[i]); sort(imena.begin(),imena.end()); int la=0; for(int i=0;i<n;i++){ int poz=lower_bound(imena.begin(),imena.end(),names[i])-imena.begin(); for(int j=0;j<16;j++){ outputs_alice[la++]=((1<<j)&numbers[i])>>j; } } return la; } // Bob int // returns lb bob( /* in */ const int m, /* in */ const char senders[][5], /* in */ const char recipients[][5], /* out */ bool outputs_bob[] ) { vector<string> imena; for(int i=0;i<m;i++){ imena.push_back(senders[i]); imena.push_back(recipients[i]); } sort(imena.begin(),imena.end()); imena.resize(unique(imena.begin(),imena.end())-imena.begin()); int n=imena.size(); vector<vector<bool> > kokome(n,vector<bool>(n,false)); for(int i=0;i<m;i++){ int ko=lower_bound(imena.begin(),imena.end(),senders[i])-imena.begin(); int kome=lower_bound(imena.begin(),imena.end(),recipients[i])-imena.begin(); kokome[ko][kome]=true; } int lb=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ outputs_bob[lb++]=kokome[i][j]; } } return lb; } int l=0; // Circuit int // returns l circuit( /* in */ const int la, /* in */ const int lb, /* out */ int operations[], /* out */ int operands[][2], /* out */ int outputs_circuit[][16] ) { auto uradi=[&](int a,int b,int op){ operations[l]=op; operands[l][0]=a; operands[l][1]=b; return l++; }; auto vise=[&](vector<int> a,int op){ int tren=a[0]; for(int i=1;i<a.size();i++){ tren=uradi(tren,a[i],op); } return tren; }; auto saberi=[&](vector<int> a,vector<int> b)->vector<int>{ int prenos=uradi(0,0,OP_ZERO); vector<int> rez(16); for(int i=0;i<16;i++){ rez[i]=vise({prenos,a[i],b[i]},OP_XOR); prenos=uradi(vise({prenos,a[i],b[i]},OP_AND),uradi(vise({prenos,a[i],b[i]},OP_OR),uradi(rez[i],0,OP_NOT_X0),OP_AND),OP_OR); } return rez; }; auto jednaki=[&](vector<int> a,vector<int> b)->int{ int tren=uradi(0,0,OP_ONE); for(int i=0;i<a.size();i++){ tren=uradi(tren,uradi(a[i],b[i],OP_EQUAL),OP_AND); } return tren; }; l=la+lb; int n=la/16; vector<vector<int> > res(n,vector<int>(16)); for(int i=0;i<n;i++){ for(int j=0;j<16;j++) res[i][j]=uradi(0,0,OP_ZERO); } for(int i=0;i<n;i++){ int ko=i; for(int kome=0;kome<n;kome++){ vector<int> vrko; for(int j=0;j<16;j++) vrko.push_back(uradi(la+i*n+kome,i*16+j,OP_AND)); res[i]=saberi(res[i],vrko); } } for(int i=0;i<n;i++){ for(int j=0;j<16;j++){ outputs_circuit[i][j]=res[i][j]; } } return l; }

컴파일 시 표준 에러 (stderr) 메시지

abc.cpp: In function 'int alice(int, const char (*)[5], const short unsigned int*, bool*)':
abc.cpp:38:13: warning: unused variable 'poz' [-Wunused-variable]
   38 |         int poz=lower_bound(imena.begin(),imena.end(),names[i])-imena.begin();
      |             ^~~
abc.cpp: In lambda function:
abc.cpp:101:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(int i=1;i<a.size();i++){
      |                     ~^~~~~~~~~
abc.cpp: In lambda function:
abc.cpp:117:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |         for(int i=0;i<a.size();i++){
      |                     ~^~~~~~~~~
abc.cpp: In function 'int circuit(int, int, int*, int (*)[2], int (*)[16])':
abc.cpp:133:13: warning: unused variable 'ko' [-Wunused-variable]
  133 |         int ko=i;
      |             ^~
abc.cpp:115:10: warning: variable 'jednaki' set but not used [-Wunused-but-set-variable]
  115 |     auto jednaki=[&](vector<int> a,vector<int> b)->int{
      |          ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...