답안 #15759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15759 2015-07-21T10:12:38 Z myungwoo 쿼터너리 컴퓨터 (kriii3_Z) C++14
126 / 126
365 ms 1728 KB
//*
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<queue>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;

int D[30];
int ord[400][4];
ll ans[30];

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i = 0; i < N; i++) scanf("%d", D+i);
	for(int i = 0; i < M; i++) scanf("%d%d%d%d", ord[i], ord[i]+1, ord[i]+2, ord[i]+3);
	for(int i = 0; i < 1<<N; i++){
		pii mem[30] = {};
		ll mul = 1;
		for(int j = 1, k = 0; j < 1<<N; j*=2, k++){
			int p = !!(i&j), q = 1 - D[k] / 2;
			mem[k].first = p;
			if( p ^ (D[k]%2 == 0) ) mem[k].second = q;
			else mem[k].second = 1<<k+1, mul = mul * 2;
		}
		for(int j = 0; j < M; j++){
			int o = ord[j][0], x = ord[j][1], y = ord[j][2], z = ord[j][3];
			pii A = mem[y], B = mem[z], C;
			if( o >= 2 ) B = pii(z%2, z/2);
			if( A.first == 1 && B.first == 1 && o%2 == 0){
				C.first = 0;
				C.second = A.second ^ B.second ^ 1;
			}
			else{
				C.first = A.first ^ B.first;
				C.second = A.second ^ B.second;
			}
			mem[x] = C;
		}
		for(int j = 0; j < N; j++){
			if( mem[j].second > 1 ) ans[j] += mul;
			else if( mem[j].second == 1 ) ans[j] += mul * 2;
			ans[j] += mem[j].first * mul;
		}
	}
	for(int i = 0; i < N; i++) printf("%lld ", ans[i]%4);
    return 0;
}
//*/
/*
#include <stdio.h>

using namespace std;
 
int N, M;
int F[18], A[18], B[18], ans[18];
 
struct Z{
    int t, x, y, z;
} Q[401];
 
void dfs(int n)
{
    if (n == N){
        for (int i=0;i<N;i++) B[i] = A[i];
        for (int i=1;i<=M;i++){
            if (Q[i].t == 0){
                B[Q[i].x] = (B[Q[i].y] + B[Q[i].z]) & 3;
            }else if (Q[i].t == 1){
                B[Q[i].x] = (B[Q[i].y] ^ B[Q[i].z]);
            }else if (Q[i].t == 2){
                B[Q[i].x] = (B[Q[i].y] + Q[i].z) & 3;
            }else{
                B[Q[i].x] = (B[Q[i].y] ^ Q[i].z);
            }
        }
        for (int i=0;i<N;i++) ans[i] = (ans[i] + B[i]) & 3;
        return;
    }
    for (int i=0;i<4;i++) if (i != F[n]){
        A[n] = i;
        dfs(n+1);
    }
}
 
int main()
{
	freopen("input.txt","r",stdin);
    scanf("%d%d", &N, &M);
    for (int i=0;i<N;i++) scanf("%d", F+i);
    for (int i=1;i<=M;i++) scanf("%d%d%d%d", &Q[i].t, &Q[i].x, &Q[i].y, &Q[i].z);
    dfs(0);
    for (int i=0;i<N;i++) printf("%d ", ans[i]); puts("");
}
//*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1728 KB Output is correct
2 Correct 0 ms 1728 KB Output is correct
3 Correct 0 ms 1728 KB Output is correct
4 Correct 0 ms 1728 KB Output is correct
5 Correct 0 ms 1728 KB Output is correct
6 Correct 0 ms 1728 KB Output is correct
7 Correct 0 ms 1728 KB Output is correct
8 Correct 1 ms 1728 KB Output is correct
9 Correct 0 ms 1728 KB Output is correct
10 Correct 0 ms 1728 KB Output is correct
11 Correct 0 ms 1728 KB Output is correct
12 Correct 0 ms 1728 KB Output is correct
13 Correct 0 ms 1728 KB Output is correct
14 Correct 0 ms 1728 KB Output is correct
15 Correct 6 ms 1728 KB Output is correct
16 Correct 6 ms 1728 KB Output is correct
17 Correct 20 ms 1728 KB Output is correct
18 Correct 23 ms 1728 KB Output is correct
19 Correct 22 ms 1728 KB Output is correct
20 Correct 21 ms 1728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 1728 KB Output is correct
2 Correct 82 ms 1728 KB Output is correct
3 Correct 163 ms 1728 KB Output is correct
4 Correct 324 ms 1728 KB Output is correct
5 Correct 40 ms 1728 KB Output is correct
6 Correct 78 ms 1728 KB Output is correct
7 Correct 156 ms 1728 KB Output is correct
8 Correct 299 ms 1728 KB Output is correct
9 Correct 46 ms 1728 KB Output is correct
10 Correct 91 ms 1728 KB Output is correct
11 Correct 186 ms 1728 KB Output is correct
12 Correct 365 ms 1728 KB Output is correct
13 Correct 43 ms 1728 KB Output is correct
14 Correct 84 ms 1728 KB Output is correct
15 Correct 166 ms 1728 KB Output is correct
16 Correct 330 ms 1728 KB Output is correct
17 Correct 45 ms 1728 KB Output is correct
18 Correct 82 ms 1728 KB Output is correct
19 Correct 161 ms 1728 KB Output is correct
20 Correct 327 ms 1728 KB Output is correct