void extend ( LegOccurrences &legoccurrencesdata, EdgeLabel minlabel, EdgeLabel neglect ) { // we're trying hard to avoid repeated destructor/constructor calls for complex types like vectors. // better reuse previously allocated memory, if possible! vector<LegOccurrence> &legoccurrences = legoccurrencesdata.elements; int lastself[candidatelegsoccurrences.size ()]; for ( int i = 0; i < candidatelegsoccurrences.size (); i++ ) { candidatelegsoccurrences[i].elements.resize ( 0 ); candidatelegsoccurrences[i].parent = &legoccurrencesdata; candidatelegsoccurrences[i].number = legoccurrencesdata.number + 1; candidatelegsoccurrences[i].maxdegree = 0; candidatelegsoccurrences[i].selfjoin = 0; lastself[i] = NOTID; candidatelegsoccurrences[i].frequency = 0; } closelegsoccsused = false; // we are lazy with the initialization of close leg arrays, as we may not need them at all in // many cases for ( OccurrenceId i = 0; i < legoccurrences.size (); i++ ) { LegOccurrence &legocc = legoccurrences[i]; DatabaseTreePtr tree = database.trees[legocc.tid]; DatabaseTreeNode &node = tree->nodes[legocc.tonodeid]; for ( int j = 0; j < node.edges.size (); j++ ) { if ( node.edges[j].tonode != legocc.fromnodeid ) { EdgeLabel edgelabel = node.edges[j].edgelabel; int number = nocycle ( tree, node, node.edges[j].tonode, i, &legoccurrencesdata ); if ( number == 0 ) { if ( edgelabel >= minlabel && edgelabel != neglect ) { vector<LegOccurrence> &candidatelegsoccs = candidatelegsoccurrences[edgelabel].elements; if ( candidatelegsoccs.empty () ) candidatelegsoccurrences[edgelabel].frequency++; else { if ( candidatelegsoccs.back ().tid != legocc.tid ) candidatelegsoccurrences[edgelabel].frequency++; if ( candidatelegsoccs.back ().occurrenceid == i && lastself[edgelabel] != legocc.tid ) { lastself[edgelabel] = legocc.tid; candidatelegsoccurrences[edgelabel].selfjoin++; } } candidatelegsoccs.push_back ( LegOccurrence ( legocc.tid, i, node.edges[j].tonode, legocc.tonodeid ) ); setmax ( candidatelegsoccurrences[edgelabel].maxdegree, database.trees[legocc.tid]->nodes[node.edges[j].tonode].edges.size () ); } } else if ( number - 1 != graphstate.nodes.back().edges[0].tonode ) { candidateCloseLegsAllocate ( number, legoccurrencesdata.number + 1 ); vector<CloseLegOccurrence> &candidatelegsoccs = candidatecloselegsoccs[number][edgelabel].elements; if ( !candidatelegsoccs.size () || candidatelegsoccs.back ().tid != legocc.tid ) candidatecloselegsoccs[number][edgelabel].frequency++; candidatelegsoccs.push_back ( CloseLegOccurrence ( legocc.tid, i ) ); setmax ( candidatelegsoccurrences[edgelabel].maxdegree, database.trees[legocc.tid]->nodes[node.edges[j].tonode].edges.size () ); } } } } }
void lcs(int ppp) { int n2=len[ppp]; int p = 0, len = 0, i, cur; for(i = 0; i < n2; i++) { cur = ss[ppp][i] - 'a'; if(st[p].next[cur] == -1) { for(; p != -1 && st[p].next[cur] == -1; p = st[p].link); if(p == -1) { p = len = 0; continue; } len = st[p].len; } len++; p = st[p].next[cur]; setmax(st[p].v, len); } for(i = 0; i < cnt; i++) { if(!b[i]) continue; setmax(st[st[b[i]].link].v, st[b[i]].v); } for(i = 0; i < cnt; i++) { setmin(st[i].w, st[i].v); st[i].v = 0; } }
int main() { freopen("Text/LCS2.txt","r",stdin); int i, k = 0, m = 0, res = 0; while(fgets(ss[k], MAX, stdin)) { len[k] = strlen(ss[k])-1; if(len[k] < len[m]) m = k; k++; } buildDFA(m); n1 = len[m]; for(i = 0; i < cnt; i++) { a[i].len = st[i].len; a[i].idx = i; } std::sort(a, a + cnt, comp); for(i = 0; i < cnt; i++) { //printf("LLLL\t%d\t%d\n",a[i].len,a[i].idx); b[i] = a[i].idx; } for(i = 0; i < k; i++) { if(i != m) lcs(i); } for(i = 0; i < cnt; i++) { setmax(res,st[i].w); } printf("%d\n", res); return 0; }
LegOccurrencesPtr join ( LegOccurrences &legoccsdata ) { if ( legoccsdata.selfjoin < minfreq ) return NULL; legoccurrences.elements.resize ( 0 ); vector<LegOccurrence> &legoccs = legoccsdata.elements; legoccurrences.maxdegree = 0; legoccurrences.selfjoin = 0; Tid lastself = NOTID; OccurrenceId j = 0, k, l, m; do { k = j; LegOccurrence &legocc = legoccs[k]; do { j++; } while ( j < legoccs.size () && legoccs[j].occurrenceid == legocc.occurrenceid ); for ( l = k; l < j; l++ ) for ( m = k; m < j; m++ ) if ( l != m ) { legoccurrences.elements.push_back ( LegOccurrence ( legocc.tid, l, legoccs[m].tonodeid, legoccs[m].fromnodeid ) ); setmax ( legoccurrences.maxdegree, database.trees[legocc.tid]->nodes[legoccs[m].tonodeid].edges.size () ); } if ( ( j - k > 2 ) && legocc.tid != lastself ) { lastself = legocc.tid; legoccurrences.selfjoin++; } } while ( j < legoccs.size () ); // no need to check that we are frequent, we must be frequent legoccurrences.parent = &legoccsdata; legoccurrences.number = legoccsdata.number + 1; legoccurrences.frequency = legoccsdata.selfjoin; // we compute the self-join frequency exactly while building the // previous list. It is therefore not necessary to recompute it. return &legoccurrences; }
// This function is on the critical path. Its efficiency is MOST important. LegOccurrencesPtr join ( LegOccurrences &legoccsdata1, NodeId connectingnode, LegOccurrences &legoccsdata2 ) { if ( graphstate.getNodeDegree ( connectingnode ) == graphstate.getNodeMaxDegree ( connectingnode ) ) return NULL; Frequency frequency = 0; Tid lasttid = NOTID; vector<LegOccurrence> &legoccs1 = legoccsdata1.elements, &legoccs2 = legoccsdata2.elements; legoccurrences.elements.resize ( 0 ); legoccurrences.maxdegree = 0; legoccurrences.selfjoin = 0; //legoccurrences.elements.reserve ( legoccs1.size () * 2 ); // increased memory usage, and speed! OccurrenceId j = 0, k = 0, l, m; unsigned int legoccs1size = legoccs1.size (), legoccs2size = legoccs2.size (); // this increases speed CONSIDERABLY! Tid lastself = NOTID; do { while ( j < legoccs1size && legoccs1[j].occurrenceid < legoccs2[k].occurrenceid ) { j++; } if ( j < legoccs1size ) { LegOccurrence &jlegocc = legoccs1[j]; while ( k < legoccs2size && legoccs2[k].occurrenceid < jlegocc.occurrenceid ) { k++; } if ( k < legoccs2size ) { if ( legoccs2[k].occurrenceid == jlegocc.occurrenceid ) { m = j; do { j++; } while ( j < legoccs1size && legoccs1[j].occurrenceid == jlegocc.occurrenceid ); l = k; do { k++; } while ( k < legoccs2size && legoccs2[k].occurrenceid == jlegocc.occurrenceid ); bool add = false; for ( OccurrenceId m2 = m; m2 < j; m2++ ) { int d = 0; for ( OccurrenceId l2 = l; l2 < k; l2++ ) { NodeId tonodeid = legoccs2[l2].tonodeid; if ( legoccs1[m2].tonodeid != tonodeid ) { legoccurrences.elements.push_back ( LegOccurrence ( jlegocc.tid, m2, tonodeid, legoccs2[l2].fromnodeid ) ); setmax ( legoccurrences.maxdegree, database.trees[jlegocc.tid]->nodes[tonodeid].edges.size () ); add = true; d++; } } if ( d > 1 && jlegocc.tid != lastself ) { lastself = jlegocc.tid; legoccurrences.selfjoin++; } } if ( jlegocc.tid != lasttid && add ) { lasttid = jlegocc.tid; frequency++; } if ( k == legoccs2size ) break; } } else break; } else break; } while ( true ); if ( frequency >= minfreq ) { legoccurrences.parent = &legoccsdata1; legoccurrences.number = legoccsdata1.number + 1; legoccurrences.frequency = frequency; return &legoccurrences; } else return NULL; }
int main (int argc, char **argv) { int c, anyflag = 0; struct passwd *pwent; Prog = Basename (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); /* try to open for read/write, if that fails - read only */ fail = fopen (FAILLOG_FILE, "r+"); if (!fail) fail = fopen (FAILLOG_FILE, "r"); if (!fail) { perror (FAILLOG_FILE); exit (1); } while ((c = getopt (argc, argv, "al:m:pru:t:")) != EOF) { switch (c) { case 'a': aflg++; if (uflg) usage (); break; case 'l': set_locktime ((long) atoi (optarg)); anyflag++; break; case 'm': setmax (atoi (optarg)); anyflag++; break; case 'p': print (); anyflag++; break; case 'r': reset (); anyflag++; break; case 'u': if (aflg) usage (); pwent = getpwnam (optarg); if (!pwent) { fprintf (stderr, _("Unknown User: %s\n"), optarg); exit (1); } uflg++; user = pwent->pw_uid; break; case 't': days = atoi (optarg); seconds = days * DAY; tflg++; break; default: usage (); } } /* no flags implies -a -p (= print information for all users) */ if (!(anyflag || aflg || tflg || uflg)) aflg++; /* (-a or -t days or -u user) and no other flags implies -p (= print information for selected users) */ if (!anyflag && (aflg || tflg || uflg)) print (); fclose (fail); return 0; /*NOTREACHED*/}
/* Communicate the fact that the fpe is reduced (and that we don't know anything more about it) */ void fpe_isreduced(fpe_t rop) { setmax(rop->v[0],(long)bn_v6/2); setmax(rop->v[6],(long)bn_v6/2); setmax(rop->v[1],(long)bn_v/2); setmax(rop->v[3],(long)bn_v/2); setmax(rop->v[4],(long)bn_v/2); setmax(rop->v[7],(long)bn_v/2); setmax(rop->v[9],(long)bn_v/2); setmax(rop->v[10],(long)bn_v/2); //XXX: Change additive constant: setmax(rop->v[2],(long)bn_v/2+2331); setmax(rop->v[5],(long)bn_v/2+2331); setmax(rop->v[8],(long)bn_v/2+2331); setmax(rop->v[11],(long)bn_v/2+2331); }
/* Communicate the fact that the fp2e is reduced (and that we don't know anything more about it) */ void fp2e_isreduced(fp2e_t rop) { setmax(rop->v[0], (long)bn_v6 / 2); setmax(rop->v[1], (long)bn_v6 / 2); setmax(rop->v[12], (long)bn_v6 / 2); setmax(rop->v[13], (long)bn_v6 / 2); setmax(rop->v[2], (long)bn_v / 2); setmax(rop->v[3], (long)bn_v / 2); setmax(rop->v[6], (long)bn_v / 2); setmax(rop->v[7], (long)bn_v / 2); setmax(rop->v[8], (long)bn_v / 2); setmax(rop->v[9], (long)bn_v / 2); setmax(rop->v[14], (long)bn_v / 2); setmax(rop->v[15], (long)bn_v / 2); setmax(rop->v[18], (long)bn_v / 2); setmax(rop->v[19], (long)bn_v / 2); setmax(rop->v[20], (long)bn_v / 2); setmax(rop->v[21], (long)bn_v / 2); //XXX: Change additive constant setmax(rop->v[4], (long)bn_v / 2 + 2331); /* TODO: Think about value */ setmax(rop->v[5], (long)bn_v / 2 + 2331); /* TODO: Think about value */ setmax(rop->v[10], (long)bn_v / 2 + 2331); /* TODO: Think about value */ setmax(rop->v[11], (long)bn_v / 2 + 2331); /* TODO: Think about value */ setmax(rop->v[16], (long)bn_v / 2 + 2331); /* TODO: Think about value */ setmax(rop->v[17], (long)bn_v / 2 + 2331); /* TODO: Think about value */ setmax(rop->v[22], (long)bn_v / 2 + 2331); /* TODO: Think about value */ setmax(rop->v[23], (long)bn_v / 2 + 2331); /* TODO: Think about value */ }
void viewNumAchievements(const vector<playerinfo>& pi, bool global) { bool gamewon = false; bool gamewon2= false; int minwound = 1000000; int minwound2= 1000000; int minvalue = 1000000; int minvalue2= 1000000; int minarm = 1000000; int minarm2 = 1000000; int minbi = 1000000; int maxjuice = -1; int maxhydra = 0; int maxambi = 0; int maxmsl = 0; int maxchrg = 0; int maxswipe = 0; int maxcoll = 0; int mots[MOT]; for(int a=0; a<MOT; a++) mots[a] = 1000000; for(int i=0; i<size(pi); i++) { const playerinfo& Pi(pi[i]); if(global ? false : Pi.username != pinfo.username) continue; if(Pi.stats.endtype >= 3) { gamewon = true; minwound = min(minwound, Pi.stats.woundwin); minvalue = min(minvalue, Pi.stats.treasure); minarm = min(minarm, Pi.stats.armscore); minbi = min(minbi, Pi.stats.bossinv); if(Pi.stats.usedup[IT_PLIFE] == 0) setmax(maxjuice, Pi.player.inv[IT_PARMS]); for(int a=0; a<MOT; a++) mots[a] = min(mots[a], Pi.stats.motwin[a]); } if(Pi.stats.endtype >= 6) { gamewon2 = true; minwound2 = min(minwound2, Pi.stats.woundwin2); minvalue2 = min(minvalue2, Pi.stats.treasure2); minarm2 = min(minarm2, Pi.stats.armscore2); } setmax(maxhydra, Pi.stats.hydrakill); setmax(maxambi, Pi.stats.maxambi); setmax(maxmsl, Pi.stats.maxmsl); setmax(maxchrg, Pi.stats.maxchrg); setmax(maxswipe, Pi.stats.maxkill); setmax(maxcoll, Pi.stats.owncrush); } erase(); col(7); addstr("Your achievements:\n\n"); if(!gamewon) addstr("You have not won the game yet.\n"); else { addstri("Minimum wounds in a winning game: "+its(minwound)+"\n"); addstri("Minimum value of used items: "+its(minvalue)+"\n"); addstri("Best mutation score: "+its(minarm)+"\n"); addstri("Least inventory items used against the boss: "+its(minbi)+"\n"); if(maxjuice < 0) addstri("You still have to win without using the Potion of Life!\n"); else { addstri("You have won without using the Potion of Life!\n"); if(maxjuice > 0) addstri("... and "+its(maxjuice)+" Potions of Power Juice!\n"); else addstri("... but you still have used all the Potions of Power Juice.\n"); } addstri("You have won using blades (-) of size at most "+its(max(mots[MOT_OBSID], mots[MOT_BLADE]))+".\n"); int nouse = 0; if(mots[MOT_BLUNT] == 0 && mots[MOT_SHLD] == 0) addstri("You have won without using blunt weapons and without shields!\n"); else if(mots[MOT_SHLD] == 0) addstri("You have won using blunt weapons of size "+its(mots[MOT_BLUNT])+" and no shields.\n"); else addstri("You have won using shields of size at most "+its(mots[MOT_SHLD])+".\n"); if(mots[MOT_OBSID] == 0) addstri("You have won without using obsidian blades.\n"), nouse++; if(mots[MOT_MSL] == 0) addstri("You have won without using missiles.\n"), nouse++; if(mots[MOT_DIV] == 0) addstri("You have won without using divisors at all!!\n"), nouse++; else if(mots[MOT_DIV] <= 2) addstri("You have won without using divisors except the Bisector!\n"), nouse++; if(nouse == 0) addstri("You have always been using obsidian blades, missiles, and large divisors.\n"); if(!gamewon2) addstri("But you still have not won the complete game!"); } addstr("\n"); if(gamewon2) { addstri("Minimum wounds in a complete winning game: "+its(minwound2)+"\n"); addstri("Minimum value of items used in a complete game: "+its(minvalue2)+"\n"); addstri("Best mutation score: "+its(minarm2)+"\n"); } addstr("\n"); addstri("Your best score was killing "+its(maxhydra)+" Hydras.\n"); if(maxambi > 0) addstri("The biggest hydra one-shotted by you had "+its(maxambi)+" heads.\n"); if(maxcoll > 1) addstri("You managed to collapse "+its(maxcoll)+" hydras in a single game!\n"); else if(maxcoll) addstri("You managed to collapse a Hydra under its own weight!\n"); if(maxmsl > 1) addstri("You managed to kill "+its(maxmsl)+" Hydras with one missile!\n"); if(maxswipe > 1) addstri("You managed to kill "+its(maxswipe)+" Hydras with one power swipe!\n"); if(maxchrg > 1) addstri("You managed to kill "+its(maxchrg)+" Hydras with one power charge!\n"); ghch(IC_VIEWDESC); }