#include #include #include #include #include #include #define INF 2100000000 #define TLIMIT 4600 #define DEADLINE 4800 using namespace std; typedef int lld; /// STRUCTURES struct FLOW { lld sx, sy, ex, ey; lld dist, id; }; FLOW Make_Flow(lld sx, lld sy, lld ex, lld ey, lld id) { FLOW ret; ret.sx = sx; ret.sy = sy; ret.ex = ex; ret.ey = ey; ret.dist = max(sx, ex) - min(sx, ex) + max(sy, ey) - min(sy, ey); ret.id = id; return ret; } struct QWE { lld x, y, prevind; }; QWE Make_QWE(lld x, lld y, lld prevind) { QWE ret; ret.x = x; ret.y = y; ret.prevind = prevind; return ret; } /// SORTING FUNCTIONS bool SH_FLOW_ByDist_DESC(FLOW a, FLOW b) { return (a.dist > b.dist); } bool SH_FLOW_ByDist_ASC(FLOW a, FLOW b) { return (a.dist < b.dist); } bool SH_FLOW_ById(FLOW a, FLOW b) { return (a.id < b.id); } ///PROGRAM lld coolx[4] = {1, -1, 0, 0}, cooly[4] = {0, 0, 1, -1}; lld n, asz; FLOW available[252]; bool forbidden[102][102], TFO[102][102], curgrid[102][102]; bool isflow[102][102]; void Input() { scanf("%d %d", &n, &asz); for (lld i=1; i<=asz; i++) { lld sx, sy, ex, ey; scanf("%d %d %d %d", &sx, &sy, &ex, &ey); sx++; sy++; ex++; ey++; isflow[sx][sy] = isflow[ex][ey] = true; available[i] = Make_Flow(sx, sy, ex, ey, i); } lld b; scanf("%d", &b); for (lld i=1; i<=b; i++) { lld x, y; scanf("%d %d", &x, &y); x++; y++; forbidden[x][y] = true; curgrid[x][y] = true; } } lld tlm = CLOCKS_PER_SEC * TLIMIT / 1000; bool HaveTime() { return (clock() < tlm); } lld ddln = CLOCKS_PER_SEC * DEADLINE / 1000; bool TryHard() { return (clock() < ddln); } bool Legit(lld x, lld y) { return (x >= 1 && x <= n && y >= 1 && y <= n); } QWE q[10002]; lld qsz; lld ranind[5]; bool FindPath_BFS(lld sx, lld sy, lld ex, lld ey, pair target[], bool stepover = false) { if (curgrid[sx][sy] || curgrid[ex][ey]) return false; //cout<<"Tursim ot "< 0); //reverse(target+1, target+indw); target[0].first = indw-1; return true; } bool FindPath_BFS(FLOW fl, pair target[], bool stepover = false) { return FindPath_BFS(fl.sx, fl.sy, fl.ex, fl.ey, target, stepover); } lld indw; bool towrite; bool FindPath_DFS(lld x, lld y, lld ex, lld ey, pair target[], bool stepover = false) { if (curgrid[x][y] || curgrid[ex][ey]) return false; //cout<<"Na "< target[], bool stepover = false) { return FindPath_DFS(fl.sx, fl.sy, fl.ex, fl.ey, target, stepover); } pair path[10002]; lld curans=0; pair ans[252][10002], info[252][10002], playtime[10002], temp[10002], best[10002]; lld Evaluate(pair info[252][10002]) { lld fcnt=0, area=0; for (lld i=1; i<=asz; i++) { if (info[available[i].id][0].first == 0) { continue; } fcnt++; area += info[available[i].id][0].first; } return fcnt*area; } void ShiftWith(lld from, lld with, pair target[]) { lld len = target[0].first; for (lld i=len; i>=from; i--) { target[i+with] = target[i]; } target[0].first += with; } void PutAfter(lld after, pair toput[], pair target[]) { ShiftWith(after+1, toput[0].first, target); for (lld i=1; i<=toput[0].first; i++) { target[after+i] = toput[i]; } } void Copy(pair source[], pair target[]) { for (lld i=0; i<=source[0].first; i++) { target[i] = source[i]; } } lld Expand(pair source[]) { lld myindw=1; lld expansion=0; if (source[0].first == 0) return 0; Copy(source, playtime); for (lld j=1; j curans) { curans = res; //cout<<"Found "< 0); //cout<