Submission #2548143


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

class ftT
{
public:
	void clear ()
	{
		INIT ( data, 0 );
	}
	
	void upd ( int p, int x )
	{
		for ( ; p < MAXN; p += p&-p ) data[p] += x;
	}
	
	int sum ( int p )
	{
		int ans = 0;
		for ( ; p; p ^= p&-p ) ans += data[p];
		return ans;
	}
	
private:
	int data[MAXN];
}ft;

int n;
int ia[MAXN][3];
int a[MAXN];
int od[MAXN], ev[MAXN], ko, ke;

void init ();
void input ();
void work ();

int getrev ( int a[], int n );



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d", &n );
	lp ( i, 0, 3 ) lpi ( j, 1, n ) scanf ( "%d", &ia[j][i] );
}

void work ()
{
	// main work
	
	int maxi, mini;
	lpi ( i, 1, n ){
		maxi = *max_element ( ia[i], ia[i]+3 ), mini = *min_element ( ia[i], ia[i]+3 );
		if ( maxi % 3 == 0 ){
			if ( mini == maxi - 2 && ia[i][0] + ia[i][1] + ia[i][2] == maxi * 3 - 3 ){
				if ( ia[i][0] < ia[i][1] && ia[i][1] < ia[i][2] ) a[i] = maxi / 3;
				else if ( ia[i][0] > ia[i][1] && ia[i][1] > ia[i][2] ) a[i] = -maxi / 3;
				else{
					printf ( "No\n" );
					return;
				}
			}else{
				printf ( "No\n" );
				return;
			}
		}else{
			printf ( "No\n" );
			return;
		}
	}
	
//	lpi ( i, 1, n ) cerr << a[i] << " "; cerr << endl;
	
	lpi ( i, 1, n ) if ( i & 1 ) od[++ko] = a[i]; else ev[++ke] = a[i];
	
	int no = 0, ne = 0, ro, re;
	
	lpi ( i, 1, ko ) if ( od[i] < 0 ) ++no;
	lpi ( i, 1, ke ) if ( ev[i] < 0 ) ++ne;
	
	ro = getrev ( od, ko );
	re = getrev ( ev, ke );
	
	printf ( ( ( no & 1 ) == ( re & 1 ) && ( ne & 1 ) == ( ro & 1 ) ) ? "Yes\n" : "No\n" );
}



int getrev ( int a[], int n )
{
	ft.clear ();
	int ans = 0;
	lpd ( i, n, 0 ){
		ans += ft.sum ( qabs ( a[i] ) );
		ft.upd ( qabs ( a[i] ), 1 );
	}
	return ans;
}

Submission Info

Submission Time
Task E - Rotate 3x3
User tqyaaaaang
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2955 Byte
Status WA
Exec Time 36 ms
Memory 2688 KB

Compile Error

./Main.cpp: In function ‘void input()’:
./Main.cpp:91:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf ( "%d", &n );
                    ^
./Main.cpp:92:58: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  lp ( i, 0, 3 ) lpi ( j, 1, n ) scanf ( "%d", &ia[j][i] );
                                                          ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1500
Status
AC × 5
AC × 76
WA × 3
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt, 1_64.txt, 1_65.txt, 1_66.txt, 1_67.txt, 1_68.txt, 1_69.txt, 1_70.txt, 1_71.txt, 1_72.txt, 1_73.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 640 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 640 KB
0_03.txt AC 1 ms 640 KB
0_04.txt AC 1 ms 640 KB
1_00.txt AC 33 ms 2560 KB
1_01.txt AC 30 ms 1408 KB
1_02.txt AC 30 ms 1408 KB
1_03.txt AC 30 ms 1536 KB
1_04.txt AC 30 ms 1408 KB
1_05.txt AC 33 ms 2560 KB
1_06.txt AC 30 ms 1408 KB
1_07.txt AC 30 ms 1408 KB
1_08.txt AC 30 ms 1408 KB
1_09.txt WA 33 ms 2560 KB
1_10.txt AC 1 ms 640 KB
1_11.txt AC 1 ms 640 KB
1_12.txt AC 1 ms 640 KB
1_13.txt AC 1 ms 640 KB
1_14.txt AC 1 ms 640 KB
1_15.txt AC 1 ms 640 KB
1_16.txt AC 1 ms 640 KB
1_17.txt AC 1 ms 640 KB
1_18.txt AC 1 ms 640 KB
1_19.txt AC 1 ms 640 KB
1_20.txt AC 1 ms 640 KB
1_21.txt AC 1 ms 640 KB
1_22.txt AC 1 ms 640 KB
1_23.txt AC 1 ms 640 KB
1_24.txt AC 1 ms 640 KB
1_25.txt AC 1 ms 640 KB
1_26.txt AC 35 ms 2560 KB
1_27.txt AC 35 ms 2560 KB
1_28.txt AC 35 ms 2688 KB
1_29.txt AC 35 ms 2560 KB
1_30.txt AC 35 ms 2560 KB
1_31.txt AC 35 ms 2560 KB
1_32.txt AC 35 ms 2560 KB
1_33.txt AC 35 ms 2560 KB
1_34.txt AC 35 ms 2560 KB
1_35.txt AC 35 ms 2560 KB
1_36.txt AC 35 ms 2560 KB
1_37.txt AC 35 ms 2560 KB
1_38.txt AC 35 ms 2560 KB
1_39.txt AC 35 ms 2560 KB
1_40.txt AC 35 ms 2560 KB
1_41.txt AC 35 ms 2560 KB
1_42.txt AC 34 ms 2560 KB
1_43.txt AC 35 ms 2560 KB
1_44.txt AC 35 ms 2560 KB
1_45.txt AC 35 ms 2560 KB
1_46.txt AC 35 ms 2560 KB
1_47.txt AC 35 ms 2560 KB
1_48.txt AC 35 ms 2560 KB
1_49.txt AC 36 ms 2560 KB
1_50.txt AC 35 ms 2560 KB
1_51.txt AC 34 ms 2560 KB
1_52.txt AC 35 ms 2560 KB
1_53.txt AC 35 ms 2560 KB
1_54.txt AC 35 ms 2560 KB
1_55.txt AC 34 ms 2560 KB
1_56.txt AC 35 ms 2560 KB
1_57.txt AC 35 ms 2560 KB
1_58.txt AC 30 ms 1408 KB
1_59.txt AC 35 ms 2560 KB
1_60.txt AC 31 ms 1536 KB
1_61.txt AC 31 ms 1792 KB
1_62.txt AC 30 ms 1536 KB
1_63.txt AC 33 ms 2560 KB
1_64.txt WA 34 ms 2560 KB
1_65.txt AC 35 ms 2560 KB
1_66.txt AC 30 ms 1664 KB
1_67.txt AC 30 ms 1536 KB
1_68.txt AC 35 ms 2560 KB
1_69.txt WA 35 ms 2560 KB
1_70.txt AC 35 ms 2560 KB
1_71.txt AC 35 ms 2560 KB
1_72.txt AC 35 ms 2560 KB
1_73.txt AC 34 ms 2560 KB