CODE FESTIVAL 2016 qual A

Submission #1227954

Source codeソースコード

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vector<pii> g[MAXN];

ll dp[MAXN];
int used[MAXN];

ll mxl, mnr;
int fl;

void dfs(int s, int ind){
	used[s] = 1;
	if (ind == 0){
		mxl = max(mxl, dp[s]);
	} else {
		mnr = min(mnr, dp[s]);
	}
	REP(i, 0, SZ(g[s])){
		int to = g[s][i]._1;
		if (!used[to]){
			dp[to] = dp[s] + g[s][i]._2;
			dfs(to, ind ^ 1);
		} else if (dp[to] != dp[s] + g[s][i]._2){
			//printf("%d %d %d %lld %lld\n", s, to, g[s][i]._2, dp[s], dp[to]);
			fl = 1;
		}
	}
}

void solve(){
	int r, c, n, x, y, a;
	scanf("%d%d%d", &r, &c, &n);
	REP(i, 0, n){
		scanf("%d%d%d", &x, &y, &a);
		g[x].pb(mp(r + y, a));
		g[r + y].pb(mp(x, -a));
	}
	REPN(i, 1, r){
		if (!used[i]){
			mxl = -INF;
			mnr = INF;
			fl = 0;
			dfs(i, 0);
			//printf("%d %lld %lld\n", fl, mxl, mnr);
			if (fl || mxl > mnr){
				printf("No\n");
				return;
			}
		}
	}
	printf("Yes\n");
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Submission

Task問題 D - マス目と整数 / Grid and Integers
User nameユーザ名 Timur Sitdikov
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 800
Source lengthソースコード長 1893 Byte
File nameファイル名
Exec time実行時間 57 ms
Memory usageメモリ使用量 16640 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘void solve()’:
./Main.cpp:65:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &r, &c, &n);
^
./Main.cpp:67:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &x, &y, &a);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt,0_03.txt,0_04.txt
All 800 / 800 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 3 ms 5248 KB
0_01.txt AC 3 ms 5248 KB
0_02.txt AC 3 ms 5248 KB
0_03.txt AC 3 ms 5248 KB
0_04.txt AC 3 ms 5248 KB
1_00.txt AC 4 ms 5632 KB
1_01.txt AC 3 ms 5632 KB
1_02.txt AC 4 ms 5632 KB
1_03.txt AC 3 ms 5376 KB
1_04.txt AC 4 ms 5632 KB
1_05.txt AC 3 ms 5248 KB
1_06.txt AC 49 ms 12800 KB
1_07.txt AC 50 ms 12800 KB
1_08.txt AC 47 ms 11392 KB
1_09.txt AC 42 ms 11392 KB
1_10.txt AC 48 ms 10368 KB
1_11.txt AC 47 ms 10368 KB
1_12.txt AC 57 ms 16640 KB
1_13.txt AC 53 ms 16640 KB
1_14.txt AC 54 ms 16640 KB
1_15.txt AC 53 ms 16640 KB
1_16.txt AC 48 ms 14336 KB
1_17.txt AC 55 ms 16384 KB
1_18.txt AC 51 ms 15616 KB
1_19.txt AC 51 ms 15744 KB
1_20.txt AC 31 ms 9088 KB
1_21.txt AC 16 ms 7680 KB
1_22.txt AC 5 ms 6144 KB
1_23.txt AC 31 ms 9856 KB
1_24.txt AC 38 ms 9984 KB
1_25.txt AC 30 ms 9088 KB
1_26.txt AC 5 ms 5760 KB
1_27.txt AC 8 ms 7040 KB
1_28.txt AC 48 ms 11520 KB
1_29.txt AC 18 ms 7936 KB
1_30.txt AC 46 ms 11136 KB
1_31.txt AC 20 ms 9088 KB
1_32.txt AC 37 ms 9344 KB
1_33.txt AC 45 ms 11136 KB
1_34.txt AC 8 ms 6784 KB
1_35.txt AC 37 ms 8192 KB
1_36.txt AC 10 ms 7040 KB
1_37.txt AC 20 ms 7680 KB
1_38.txt AC 35 ms 10112 KB
1_39.txt AC 13 ms 7936 KB
1_40.txt AC 35 ms 9856 KB
1_41.txt AC 18 ms 8960 KB
1_42.txt AC 40 ms 9984 KB
1_43.txt AC 30 ms 9600 KB
1_44.txt AC 38 ms 10112 KB
1_45.txt AC 13 ms 7168 KB
1_46.txt AC 44 ms 10880 KB
1_47.txt AC 16 ms 7680 KB
1_48.txt AC 15 ms 7040 KB
1_49.txt AC 7 ms 6656 KB
1_50.txt AC 26 ms 8576 KB
1_51.txt AC 44 ms 11008 KB
1_52.txt AC 6 ms 7168 KB
1_53.txt AC 10 ms 7552 KB
1_54.txt AC 16 ms 7680 KB
1_55.txt AC 19 ms 7296 KB
1_56.txt AC 32 ms 9472 KB
1_57.txt AC 47 ms 11264 KB
1_58.txt AC 39 ms 10368 KB
1_59.txt AC 6 ms 6656 KB
1_60.txt AC 3 ms 5248 KB
1_61.txt AC 3 ms 5248 KB
1_62.txt AC 3 ms 5248 KB
1_63.txt AC 3 ms 5248 KB