제출 #794673

#제출 시각아이디문제언어결과실행 시간메모리
794673FEDIKUS앨리스, 밥, 서킷 (APIO23_abc)C++17
0 / 100
188 ms10960 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<5;j++){ outputs_alice[la++]=((1<<j)&poz)>>j; } for(int j=0;j<16;j++){ outputs_alice[la++]=((1<<j)&numbers[i])>>j; } } for(int i=0;i<la;i++){ cout<<outputs_alice[i]<<" "; if(i%21==20) cout<<"\n"; } 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 lb=0; for(int i=0;i<m;i++){ int poz=lower_bound(imena.begin(),imena.end(),senders[i])-imena.begin(); for(int j=0;j<5;j++){ outputs_bob[lb++]=((1<<j)&poz)>>j; } poz=lower_bound(imena.begin(),imena.end(),recipients[i])-imena.begin(); for(int j=0;j<5;j++){ outputs_bob[lb++]=((1<<j)&poz)>>j; } } for(int i=0;i<lb;i++){ cout<<outputs_bob[i]<<" "; if(i%10==9) cout<<"\n"; } 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/21; int m=lb/10; 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++){ vector<int> trenutni; for(int j=i*21;j<i*21+5;j++) trenutni.push_back(j); for(int j=0;j<m;j++){ vector<int> ko; for(int i=j*10;i<j*10+5;i++) ko.push_back(la+i); vector<int> kome; for(int i=j*10+5;i<j*10+10;i++) kome.push_back(la+i); int dobar=jednaki(kome,trenutni); vector<int> vrko(16); for(int j=0;j<16;j++) vrko[j]=uradi(0,0,OP_ZERO); for(int i=0;i<n;i++){ vector<int> ovajlik; for(int j=i*21;j<i*21+5;j++) ovajlik.push_back(j); int dobarlik=jednaki(ovajlik,ko); for(int j=0;j<16;j++){ vrko[j]=uradi(vrko[j],vise({dobar,dobarlik,i*21+5+j},OP_AND),OP_OR); } } 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 lambda function:
abc.cpp:108:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |         for(int i=1;i<a.size();i++){
      |                     ~^~~~~~~~~
abc.cpp: In lambda function:
abc.cpp:124:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |         for(int i=0;i<a.size();i++){
      |                     ~^~~~~~~~~
#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...